Announcing Marpa's Scanless interface
[ This is cross-posted from the new home of the Ocean of Awareness blog. ]
Marpa::R2's Scanless interface is now out of beta and available in full release on CPAN. This interface allows Marpa to be used without the need to create a separate lexer (scanner), and increases Marpa's level of "whipitupitude". Here's what a simple calculator looks like in the Scanless interface:
:start ::= Script Script ::= Expression+ separator => comma action => do_script comma ~ [,] Expression ::= Number | '(' Expression ')' action => do_parens assoc => group || Expression '**' Expression action => do_pow assoc => right || Expression '*' Expression action => do_multiply | Expression '/' Expression action => do_divide || Expression '+' Expression action => do_add | Expression '-' Expression action => do_subtract Number ~ [\d]+ :discard ~ whitespace whitespace ~ [\s]+ # allow comments :discard ~ <hash comment> <hash comment> ~ <terminated hash comment> | <unterminated final hash comment> <terminated hash comment> ~ '#' <hash comment body> <vertical space char> <unterminated final hash comment> ~ '#' <hash comment body> <hash comment body> ~ <hash comment char>* <vertical space char> ~ [\x{A}\x{B}\x{C}\x{D}\x{2028}\x{2029}] <hash comment char> ~ [^\x{A}\x{B}\x{C}\x{D}\x{2028}\x{2029}]
The full example, with semantics, is in a Github gist. It is almost identical to the example in the Scanless interface documents, and to a test in Marpa::R2's test suite.
Marpa's BNF interface came out of beta and into full release at the same time as the Scanless interface. Like the Scanless interface, the BNF interface allows you to write your grammar in a BNF variant. Unlike the Scanless interface, it requires you to do your own lexing.
The Scanless interface is a superset of the BNF interface, so the documentation of the BNF interface is the best place to start for learning both. However, to work with either, you probably should already have at least some familiarity with Marpa's standard interface.
Not long ago, my work on Marpa was a lone endeavour. One sign of Marpa's emergence is that my work now is often based on insights gained by others who have used Marpa. The BNF interface is based on one written by Peter Stuifzand. And the approach to scannerless parsing that I finally settled on was suggested to me by Andrew Rodland's prior work on pairing Marpa grammars.
Comments
Comments on this post
can be sent to the Marpa Google Group:
marpa-parser@googlegroups.com