Google Groups

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


Peter Stuifzand Sep 26, 2012 1:23 AM
Posted in group: marpa parser
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