three18ti has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: [Marpa::R2] Help with EBNF Grammar Formatting (SLIF is more BNF than EBNF)
by Anonymous Monk on Nov 10, 2013 at 01:49 UTC | |
by Anonymous Monk on Nov 10, 2013 at 01:56 UTC | |
by three18ti (Monk) on Nov 10, 2013 at 02:26 UTC | |
by Anonymous Monk on Nov 10, 2013 at 02:38 UTC | |
by three18ti (Monk) on Nov 10, 2013 at 19:00 UTC |