Re:“2015 will be the year that Perl 6 officially launches fo...
by rurban on Friday November 07, 2014 @10:09AM
(#8572806)
With perl6 the peg backend is built-in, so you can compile and execute grammars on the fly. A bit like lua's lpeg.
A perl6 Grammar is a first-class object.
Re:“2015 will be the year that Perl 6 officially launches fo...
by nly on Friday November 07, 2014 @10:53AM
(#8573050)
Sure, but what happens when someone needs something other than PEG/recursive descent, like expression parsing with a custom precedence table? Will Perl6 add that to the core language as well? Where do you draw the line?
LPeg is a library, Spirit X3 (for C++, not yet complete) is a library. Both achieve pretty seamless integration with your code. I think in a library is where this stuff should be.
Re:“2015 will be the year that Perl 6 officially launches fo...
by arnsholt on Friday November 07, 2014 @11:48AM
(#8573384)
It's pretty easy (to the extent that implementing custom parsing logic is ever easy) to add custom parsing bits to a Perl 6 grammar.
The grammar is just a special class with the rules as methods, so rules with non-standard parsing logic can be implemented using Perl 6 code. Reusing standard rules from custom rules is simply a matter of calling the corresponding method.
The best example of this is probably the EXPR rule in the NQP compiler (which is in turn used by Rakudo's parser), which inserts an operator precedence parser into the recursive descent of the rest of the grammar.
Even in C you can use something like Ian Piumarta's PEG generator[0] that let's you embed semantic actions written in C. For regular grammars, scanners and lexers you have powerful tools like Ragel[1] (which targets 7 languages)
I'm not a Python person, so if the Python libraries proved inadequate I'd probably resort to these tools and then push out a Python module using Cyphon[2].
Personally I'm not a fan of using semantic actions for AST construction. I generally prefer the 'attribute' approach taken by libraries like Spirit (C++) which make the process feel a lot more like deserialization. SAs are still useful however for rejecting or accepting rules based on complex requirements (like "is this IP address routable"?).
[0] http://piumarta.com/software/peg/ [1] http://www.colm.net/open-source/ragel/ [2] http://cython.org/