Skip to content

Commit

Permalink
Work on blog post
Browse files Browse the repository at this point in the history
  • Loading branch information
- committed Nov 16, 2012
1 parent e18af14 commit 99a2015
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions blog/incremental/incremental.pl
Expand Up @@ -34,8 +34,8 @@ sub usage {
my $show_position_flag;
my $quiet_flag;
my $getopt_result = GetOptions(
"n!" => \$show_position_flag,
"q!" => \$quiet_flag,
"n!" => \$show_position_flag,
"q!" => \$quiet_flag,
);
usage() if not $getopt_result;

Expand All @@ -44,17 +44,18 @@ sub usage {
sub do_undef { undef; }
sub do_arg1 { $_[2]; }
sub do_what_I_mean { shift; return $_[0] if scalar @_ == 1; return \@_ }

sub do_target {
my $origin = (Marpa::R2::Context::location())[0];
return undef if $origin != $ORIGIN;
return $_[1];
}
my $origin = ( Marpa::R2::Context::location() )[0];
return undef if $origin != $ORIGIN;
return $_[1];
} ## end sub do_target

my $grammar = Marpa::R2::Grammar->new(
{ start => 'start',
actions => 'main',
{ start => 'start',
actions => 'main',
default_action => 'do_what_I_mean',
rules => [ <<'END_OF_RULES' ]
rules => [ <<'END_OF_RULES' ]
start ::= prefix target action => do_arg1
prefix ::= any_token* action => do_undef
target ::= expression action => do_target
Expand Down Expand Up @@ -189,7 +190,7 @@ sub My_Error::last_completed_range {
TOKEN_TYPE: for my $t (@lexer_table) {
my ( $token_name, $regex ) = @{$t};
next TOKEN_TYPE if not $string =~ m/\G($regex)/gcxms;
if ( not defined $recce->alternative($token_name, \$1) ) {
if ( not defined $recce->alternative( $token_name, \$1 ) ) {
pos $string = $position; # reset position for matching
next TOKEN_TYPE;
}
Expand Down Expand Up @@ -236,17 +237,18 @@ sub My_Error::input_slice {
print qq{$origin-$end: } if $show_position_flag;
say $slice;
$recce->set( { end => $end } );
my $parse_count = 0;
VALUE: while (1) {
my $value;
VALUE: while (not defined $value) {
local $ORIGIN = $origin;
my $value_ref = $recce->value();
last VALUE if not defined $value_ref;
$parse_count++;
my $value = ${$value_ref};
next VALUE if not defined $value;
say Data::Dumper::Dumper($value) if not $quiet_flag;
$value = ${$value_ref};
} ## end VALUE: while (1)
say 'No parse' if not $parse_count;
if (not defined $value) {
say 'No parse';
next RESULT;
}
say Data::Dumper::Dumper($value) if not $quiet_flag;
$recce->reset_evaluation();
} ## end RESULT: for my $result ( reverse @results )

Expand Down

0 comments on commit 99a2015

Please sign in to comment.