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

10 views
Skip to first unread message

rns

unread,
Sep 26, 2012, 4:11:13 AM9/26/12
to marpa-...@googlegroups.com
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)] ],

Peter Stuifzand

unread,
Sep 26, 2012, 4:23:04 AM9/26/12
to marpa-...@googlegroups.com
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

rns

unread,
Sep 26, 2012, 4:29:54 AM9/26/12
to marpa-...@googlegroups.com
So it's undocumented, unofficial and thus needs to be avoided, thanks for explaining.

Peter Stuifzand

unread,
Sep 26, 2012, 4:33:42 AM9/26/12
to marpa-...@googlegroups.com
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


rns

unread,
Sep 26, 2012, 4:39:28 AM9/26/12
to marpa-...@googlegroups.com


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

unread,
Sep 26, 2012, 4:46:01 AM9/26/12
to marpa-...@googlegroups.com
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


rns

unread,
Sep 26, 2012, 5:04:10 AM9/26/12
to marpa-...@googlegroups.com
Ah, yes. Tim Toady in action. Thanks again for explaining.
Reply all
Reply to author
Forward
0 new messages