Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An option for hy to *only* check syntax #689

Closed
kozross opened this issue Nov 20, 2014 · 8 comments
Closed

An option for hy to *only* check syntax #689

kozross opened this issue Nov 20, 2014 · 8 comments
Labels

Comments

@kozross
Copy link

kozross commented Nov 20, 2014

I'm writing a syntax checker for Hy in Flycheck at the moment, and have hit a bit of a stumbling block. At the moment, the only (easy...) way to syntax-check Hy source code is to pump it through hy and hope it executes. This isn't very desirable in a Flycheck checker, as it means executing (again and again) code that may take a long time to run or have side effects we don't want.

Would it be possible to add a flag to hy (I suggest -c) which only checks it for syntactic validity? It would spew the same errors as hy does now if the code isn't syntactically valid (or it can't find the module or whatever), and do nothing but return success otherwise?

@paultag
Copy link
Member

paultag commented Nov 20, 2014

Yeah that sounds awesome! :D

Perhaps also machine readable lexer errors!

On Thu, Nov 20, 2014 at 2:02 PM, Koz Ross notifications@github.com wrote:

I'm writing a syntax checker for Hy in Flycheck at the moment, and have
hit a bit of a stumbling block. At the moment, the only (easy...) way to
syntax-check Hy source code is to pump it through hy and hope it
executes. This isn't very desirable in a Flycheck checker, as it means
executing (again and again) code that may take a long time to run or have
side effects we don't want.

Would it be possible to add a flag to hy (I suggest -c) which only checks
it for syntactic validity? It would spew the same errors as hy does now
if the code isn't syntactically valid (or it can't find the module or
whatever), and do nothing but return success otherwise?


Reply to this email directly or view it on GitHub
#689.

:wq

@refi64
Copy link
Contributor

refi64 commented Nov 20, 2014

If you just want to check for syntatical/macro errors:

$ alias hycheck="python -c \"import hy.lex, hy.compiler, sys; hy.compiler.hy_compile(hy.lex.tokenize(sys.stdin.read()), '__console__')\""

From then on, you can just do:

$ hycheck < myfile.hy

@kozross
Copy link
Author

kozross commented Nov 20, 2014

@kirbyfan64 This will only check syntax - not invalid imports, undefined functions, etc. I guess that stuff is all done at runtime, which basically means that I'd have to write a linter for Hy if I wanted that stuff checked. Well, I guess I can do that - in Hy!

I have three ideas for names:

  1. hylite (oh god, the puns, plz stop)
  2. crazyrap (source)
  3. back2school (source)

@rakete
Copy link

rakete commented Nov 25, 2014

I would like to have error checking for hy with flycheck as well, so I tried to make pylint work with hy:
https://gist.github.com/rakete/2699be18d4218685c66d

This seems to actually work. Pylint just uses an python ast, and it takes one created by hy just fine. Some of the warnings don't make much sense though and I have not spend a lot of time playing with different (and more complex) hy sources yet. Basic things like getting told when I use an undefined variable or unused arguments and stuff like that are already a huge success for me.

@xificurC
Copy link

Is there anything done on this part? It's marked as good-first-bug but it seems like a bigger project (to write a full-blown linter)

@Kodiologist
Copy link
Member

No, nobody has worked on this since. Presumably @berkerpeksag marked it good-first-bug on the assumption that you'd either use a method like Kirby suggested or use pylint. But in any case, I'd tend to think it's not a very good first bug.

@Kodiologist
Copy link
Member

Beware that once we have reader macros, which seems likely to happen (#2242), syntactic correctness will become Turing-undecidable. That is, you'll have to compile and macroexpand everything in order to check the syntax, which can involve running arbitrary code. Perl has a similar problem due to BEGIN blocks.

@Kodiologist
Copy link
Member

Yeah, considering that issue, this feature would probably not be very helpful, and it would be dangerous because people would probably use it not realizing that it can run arbitrary code. You could implement an approximation of some sort, like checking that code with no reader macros is syntactically correct in terms of what can be analyzed statically, but that's probably something best implemented as an external tool than a feature of Hy itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants