Created
January 3, 2013 10:21
-
-
Save pstuifzand/4442448 to your computer and use it in GitHub Desktop.
test script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use Marpa::R2 2.038000; | |
use Data::Dumper; | |
my $grammar = Marpa::R2::Scanless::G->new( | |
{ | |
action_object => 'My_Actions', | |
default_action => 'do_first_arg', | |
source => \(<<'END_OF_SOURCE'), | |
:start ::= Number | |
Number ::= number+ # If I add '+' or '*' it will work... | |
number ~ [\d]+ | |
:discard ~ whitespace | |
whitespace ~ [\s]+ | |
END_OF_SOURCE | |
} | |
); | |
sub my_parser { | |
my ( $grammar, $input_string ) = @_; | |
my $recce = Marpa::R2::Scanless::R->new( { grammar => $grammar } ); | |
my $self = bless { grammar => $grammar }, 'My_Actions'; | |
$self->{recce} = $recce; | |
local $My_Actions::SELF = $self; | |
$recce->read($input_string); | |
my $value_ref = $recce->value(); | |
return ${$value_ref}; | |
} ## end sub my_parser | |
my $value = my_parser($grammar, \"1"); | |
print Dumper($value); | |
package My_Actions; | |
our $SELF; | |
sub new {return $SELF } | |
sub do_first_arg { shift; return shift; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment