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

Showing 1-7 of 7 messages
[ lhs => [qw(symbol1 symbol2)], 'sub_name' ] syntax rns 9/26/12 1:11 AM
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)] ],
Re: [ lhs => [qw(symbol1 symbol2)], 'sub_name' ] syntax Peter Stuifzand 9/26/12 1:23 AM
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
Re: [ lhs => [qw(symbol1 symbol2)], 'sub_name' ] syntax rns 9/26/12 1:29 AM
So it's undocumented, unofficial and thus needs to be avoided, thanks for explaining.
Re: [ lhs => [qw(symbol1 symbol2)], 'sub_name' ] syntax Peter Stuifzand 9/26/12 1:33 AM
No, it is documented. I even included a link to the documentation.
Method (2) is used in MarpaX::Simple::Lexer example.

--
Peter Stuifzand | peterstuifzand.nl | @pstuifzand


Re: [ lhs => [qw(symbol1 symbol2)], 'sub_name' ] syntax rns 9/26/12 1:39 AM


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.
Re: [ lhs => [qw(symbol1 symbol2)], 'sub_name' ] syntax Peter Stuifzand 9/26/12 1:46 AM
In Perl you can write these things in two ways. The => operator is
called a fat comma, which can be used (almost?) everywhere where a
comma can be used. But on top of that the fat comma also stringifies
the left side. That would mean that

     [ conditition => [ qw(word) ] ]

is the same as

     [ 'conditition', [ qw(word) ] ]

See this manpage:
http://perldoc.perl.org/perlop.html#Comma-Operator and
http://en.wikipedia.org/wiki/Fat_comma


--
Peter Stuifzand | peterstuifzand.nl | @pstuifzand


Re: [ lhs => [qw(symbol1 symbol2)], 'sub_name' ] syntax rns 9/26/12 2:04 AM
Ah, yes. Tim Toady in action. Thanks again for explaining.