Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking syntax of a string or file

Tags:

raku

Is there any internal (as in memory-only) equivalent to running perl6 -c on a file to check the syntax? So far, there are two methods

  • Running EVAL, but this actually runs the code. It's fast, but might cause some memory problems if evaluated structures are not garbage-collected
  • Creating a temporal file and running perl6 -c over it, but as said above, this is safe but an order of magnitude slower.

I am looking for a safe (as in perl6 -c) and fast (as in EVAL) alternative. Any idea?

like image 244
jjmerelo Avatar asked May 17 '19 16:05

jjmerelo


People also ask

How do I check the syntax of a python script?

How to check the syntax of your Python code: First, Drag and drop your Python file or copy / paste your Python text directly into the editor above. Finally, you must click on "Check Python syntax" button to start code checking.


1 Answers

As noted in the comments above, Raku now supports this by letting you pass the :check named parameter to EVALFILE (to check the syntax of a file) or to EVAL (to check the syntax of a string). In either case, the function will return Nil if the syntax is valid and will throw the relevant exception if it is not.

like image 61
codesections Avatar answered Oct 14 '22 22:10

codesections