Search code examples
raku

Checking syntax of a string or file


Is there any internal (as in memory-only) equivalent to running raku -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?


Solution

  • 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.