6 ms·
> my point is that it's much harder to resynchronize with a context-free grammar. So, don't use a context free grammar. [1] Use something else, eg a PEG. [2]
by raiph 12y ago
> my point is that it's much harder to resynchronize with a context-free grammar.
So, don't use a context free grammar. [1]
Use something else, eg a PEG. [2]
Not only are Perl 6 grammars PEGs, not CFGs, but individual rules are closures (of arbitrary code) as well as input matchers so one can write arbitrary code to handle anything that happens during a parse. [3]
As a very trivial example, in a grammar I wrote for parsing a CPAN control file, I added a rule for handling unexpected field types. It prints a warning to stderr and then keeps on going. [4]
Imo Perl 6 is, among its many strengths, an innovative parsing tool with at least three big problems right now:
* The grammar engine is slow. [5]
* Cat is likely a post Perl 6.0.0 feature. (Among other things, Cat is for enabling practical parsing of arbitrarily long and arbitrarily buffered data streams without having to tweak userland code.) [6]
* Macro, slang and parse tweaking features are still evolving. [7]
[1] http://en.wikipedia.org/wiki/Context-free_grammar http://en.wikipedia.org/wiki/Context-free_grammar
[2] http://en.wikipedia.org/wiki/Parsing_expression_grammar http://en.wikipedia.org/wiki/Parsing_expression_grammar
[3] http://en.wikipedia.org/wiki/Perl_6_rules http://en.wikipedia.org/wiki/Perl_6_rules
[4] https://gist.github.com/raiph/63508a5f4ade000acc7f https://gist.github.com/raiph/63508a5f4ade000acc7f
See the `data-item:dst_GENERIC-MATCH` rule; note the embedded `{ warn ... }` closure.
[5] http://www.reddit.com/r/perl6/comments/2ec2hd/rakudo_perl_6_and_moarvm_performance_advances_in/ http://www.reddit.com/r/perl6/comments/2ec2hd/rakudo_perl_6_...
[6] http://perlcabal.org/syn/S03.html http://perlcabal.org/syn/S03.html which includes:
"The Cat type allows you to have an infinitely extensible string. ... Then a Regex can be used against it as if it were an ordinary string ... The Cat interface allows the regex to match element boundaries with the <,> assertion ... Strings, arrays, lists, sequences, captures, and tree nodes can all be pattern matched by regexes or by signatures more or less interchangeably."
[7] http://perl6advent.wordpress.com/2014/12/17/day-17-three-strange-loops/ http://perl6advent.wordpress.com/2014/12/17/day-17-three-str...