Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gistfile1.pl:
- use strict; use warnings; use 5.010;
- use Data::Dumper;
- my $data = <<'END';
- for each order ArtCod ArtSucMov ArtCodMov
- ArtFchPrcMes = &Fch
- endfor
- END
- my $ast = Parser->parse(\$data);
- print Dumper $ast;
- # Below is a class that wraps the Marpa Parser
- package Parser;
- use Marpa::R2;
- my ($grammar);
- sub parse {
- my ($self, $ref) = @_;
- my $recce = Marpa::R2::Scanless::R->new({ grammar => $grammar });
- $recce->read($ref);
- my $val = $recce->value // die "No parse found";
- return $$val;
- }
- BEGIN {
- $grammar = Marpa::R2::Scanless::G->new({
- bless_package => 'Ast',
- source => \<<'END SOURCE',
- :default ::= action => [values]
- :start ::= StatementList
- :discard ~ ws
- StatementList ::=
- ForEachLoop
- | AttrAssignment
- ForEachLoop ::= 'for each' AttributeList StatementList ('endfor')
- AttrAssignment ::= Attribute '=' Expression1
- AttributeList ::= AttributeList Attribute
- Attribute ::= word
- Expression1 ::= variable
- variable ::= ampersand word
- ampersand ~ '&'
- word ~ [\w]+
- ws ~ [\s]+
- # newline ~ '\n'
- END SOURCE
- });
- }
- $ perl ./gistfile1.pl
- Unproductive symbol: AttributeList
- Unproductive symbol: ForEachLoop
- Error in SLIF parse: No lexemes accepted at line 1, column 1
- Rejected lexeme #0: 'for each'; value="for each"; length = 8
- * String before error:
- * The error was at line 1, column 1, and at character 0x0066 'f', ...
- * here: for each order ArtCod ArtSucMov ArtCodMov\n Art
- Marpa::R2 exception at ./gistfile1.pl line 25.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement