Hello Monks

We have a sudoers file that is a mess. I'm attempting to parse it out, and after a few attempts to basically roll my own parser, I found Marpa. I've read through the tutorial, and I thought I understood, so I build my grammar spec based on the Sudoers Manual... I was getting errors so I am attempting to break down my grammar into little pieces and build the grammar back up to the full spec.

I'm definitely missing something because I don't see anything wrong, but I'm getting an error...

Here's my small sample code:

#!/usr/bin/env perl use strict; use warnings; use warnings; use Marpa::R2; my $grammar_spec = get_grammar(); my $test_input = test_input(); my $grammar = Marpa::R2::Scanless::G->new({ source => \$grammar_spec, +}); my $recce = Marpa::R2::Scanless::R->new({ grammar => $grammar }); $recce->read(\$test_input); my $val = $recce->value; sub get_grammar { return <<'END_GRAMMAR'; :start ::= Alias :discard ~ ws Alias ::= 'User_Alias' User_Alias (':' User_Alias)* User_Alias ::= NAME '=' User_List User_List ::= User | User ',' User_List User ::= <user name> NAME ~ [A-Z]([A-Z][0-9]_)* ws ~ [\s]+ <user name> ~ [a-z]([a-z][0-9]_)* END_GRAMMAR } sub test_input { return <<'END_INPUT'; User_Alias FOO = abc, def END_INPUT }

The error I get is:

Error in SLIF parse: No lexemes accepted at line 4, column 70 * String before error: ::= 'User_Alias' User_Alias (':' User_Ali +as) * The error was at line 4, column 70, and at character 0x002a '*', ... * here: *\n User_Alias ::= NAME '=' User_List\n Marpa::R2 exception at test.pl line 10.

This seems to indicate the error is in the line:

Alias ::= 'User_Alias' User_Alias (':' User_Alias)*

rewriting the Alias definition:

Alias ::= 'User_Alias' User_Alias

Returns a new error:

Error in SLIF parse: No lexemes accepted at line 10, column 45 * String before error: ame>\n NAME ~ [A-Z]([A-Z][0-9 +]_) * The error was at line 10, column 45, and at character 0x002a '*', .. +. * here: *\n ws ~ [\\s]+\n <user nam Marpa::R2 exception at test.pl line 10.

So I'm thinking the problem lies in the second iteration of "User_Alias" i.e.: (':' User_Alias)* ... I'm just not sure what the problem is.

Also, the second error seems to indicate an issue with my NAME definition. column 40 is the dash between the 0 and 9 in "(A-Z0-9_)*"

I appreciate any thoughts or assistance.

Thanks!


In reply to [Marpa::R2] Help with EBNF Grammar Formatting by three18ti

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.