On Sat, May 07, 2016 at 09:54:42PM +0800, Richard Hainsworth wrote: : Hi, : In S05, I found: : "Although the default |<.ws>| subrule recognizes no comment : construct, any grammar is free to override the rule. The |<.ws>| : rule is not intended to mean the same thing everywhere." : : I was looking for an example of a new rule to deal with comments. Any links?
Well, the nqp and perl6 grammars override ws in various ways, so you could check out those for ideas. (In particular, the perl6 grammar ends up calling out to a comment proto rule, to support multiple kinds of comment as multi tokens, though the grammar does not yet recognize user-defined comment:</* */> definitions, alas.) : Or, can anyone suggest an rule that handles C type comments? The default in user-defined grammars is this: token ws { [ \s+ | '#' \N* ]* } so if you just want C-style instead of shell style, use something like this: token ws { [ \s+ | '/*' .*? '*/' ]* } or slightly fancier: token ws { [ \s+ | '/*' ~ '*/' .*? ]* } The latter form allows you to define a FAILGOAL rule to give an error message when it can't find the closing '*/'. Larry