During the waiting-time in today's porcelain painting session, I finally figured out the way to implement the "any line ending in a semicolon (except for whitespace) can terminate a statement" rule:
my &foo := {
say 1;
say 2;
} # Look, no semicolon!
my &bar := {
say 3;
say 4;
} # ditto
See S04: Statement-ending Blocks for details. The solution turns out to rely on a Parsec feature: setInput, that tells the rest of the parsing to operate on a different string, instead of the current one. With this, for statement-level parsing, we can parse the block (up to the closing '}'), mark the position, parse some whitespace, and see if the line number has changed. If yes, then it's a statement-ending block, and we insert a semicolon right there. However, I wonder how to port this trick into Perl 6 rules...
Also I implemented .[0] and .<name> (shorthand for $_[0] and $_<name>), as well as the nice "@foo .= map(&sqrt)" mutating-method idiom. During the discussion in #perl6 that followed, I then stumbled upon a possible solution to the long dot not short enough problem -- thanks Juerd++ for the excellent summary on the perl6-language list!
Comments
You can follow this conversation by subscribing to the comment feed for this post.