Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

particle (3326)

particle
  (email not shown publicly)

Journal of particle (3326)

Wednesday January 09, 2008
07:04 PM

[perl6]: implement syntax checking (-c)

[ #35343 ]

similar to previous entries on adding command line options to perl6, here i'm adding a syntax check option, '-c'. in order to do this, i've added a custom syntax checking stage to the compiler stages after the abstract syntax tree has been generated. this ensures that 'BEGIN' and 'CHECK' blocks have been executed before syntax is checked, which matches Perl 5's behavior.

view the patch here: http://perlsix.org/svn/parrot/revision/?rev=24712

the first difference takes the attribute values that were previously inherited directly from 'PCT::HLLCompiler' and moves them into 'Perl6::Compiler', so i can modify them. i've added a new stage called 'check_syntax' after the 'past' stage, and added the 'c' option to the list of command line options.

the next difference adds usage text for '-c'.

the last difference implements the 'check_syntax' compiler method. like other compiler stages (found in 'PCT::HLLCompiler', 'check_syntax' has two formal parameters: 'source' is the object that is expected as input, and 'adverbs' is a hash containing options passed in to that compiler stage.

q{ $I0 = adverbs['c'] } tells me if the '-c' option has been passed to perl6. if it hasn't been passed, then return and move on. if '-c' has been passed, then we're checking syntax. now here's a big cheat, because if i've made it to the 'check_syntax' method, i must have generated valid PAST already, which means syntax checks out OK. so, i print out a nice message and exit gracefully. if there has been a parsing error, a previous compiler method ('parse' or 'past') would have complained and displayed the errors with backtrace info to the user.

this isn't quite perfect, but it's a good first approximation--indeed good enough to be useful, and a simple example of adding a compiler stage to a compiler built with PCT.

related links:

PCT::HLLCompiler source:
http://svn.perl.org/parrot/trunk/compilers/pct/src/PCT/HLLCompiler.pir

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.