Google Groups

Re: [ lhs => [qw(symbol1 symbol2)], 'sub_name' ] syntax


rns Sep 26, 2012 1:39 AM
Posted in group: marpa parser


On Wednesday, September 26, 2012 11:33:42 AM UTC+3, Peter Stuifzand wrote:
No, it is documented. I even included a link to the documentation.
Method (2) is used in MarpaX::Simple::Lexer example.
MarpaX::Simple::Lexer uses [ condition => [qw(word)] ], a key/value pair in a array (rather than hash) that seems to be undocumented.
 

--
Peter Stuifzand | peterstuifzand.nl | @pstuifzand


On Wed, Sep 26, 2012 at 10:29 AM, rns <sor...@gmail.com> wrote:
> So it's undocumented, unofficial and thus needs to be avoided, thanks for
> explaining.
>
> On Wednesday, September 26, 2012 11:23:05 AM UTC+3, Peter Stuifzand wrote:
>>
>> There are two ways to specify rules:
>>
>> 1. Hashes (key/value pairs)
>>
>>     { lhs => 'Term', rhs => [qw/Term Add Term/], action => 'do_add' }
>>
>>
>> 2. Arrays with short form syntax.
>> https://metacpan.org/module/Marpa::R2::Grammar#Rule-descriptors-as-arrays
>>
>>     [ 'Term', [qw/Term Add Term/], 'do_add' ]
>>
>> So that would be:
>>
>>    [ lhs, rhs, action ]
>>
>> where both rhs and action are optional. The rhs part should be an
>> array ref. You can't include more key/value type options in this
>> syntax. If you want that, you have to use the first method.
>>
>> --
>> Peter Stuifzand | peterstuifzand.nl | @pstuifzand
>>
>>
>> On Wed, Sep 26, 2012 at 10:11 AM, rns <sor...@gmail.com> wrote:
>> > Is _subj_ (used, e.g., in [1] Marpa-Simple-Lexer [1]) official?
>> >
>> > It worked for me in Marpa::R2 but will it be supported? I've found
>> > nothing
>> > about it in the R2's doc so it's probably not.
>> >
>> > A list of key/value pairs, e.g. [ lhs => [qw(symbol1 symbol2)], action
>> > =>
>> > 'sub_name' ] doesn't work in R2 and probably shouldn't.
>> >
>> > I kind of like the terseness.
>> >
>> > [1]
>> >>
>> >>         [ condition => [qw(word)] ],
>> >>         [ condition => [qw(quoted)] ],
>> >>         [ condition => [qw(OPEN-PAREN SPACE? query SPACE? CLOSE-PAREN)]
>> >> ],
>> >>         [ condition => [qw(NOT condition)] ],
>> >>
>> >>         [ 'SPACE?' => [] ],
>> >>         [ 'SPACE?' => [qw(SPACE)] ],
>> >
>> > —
>> > https://github.com/ruz/Marpa-Simple-Lexer/blob/master/examples/synopsis.pl