Skip to content

Commit

Permalink
Work on SL parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
- committed Nov 15, 2012
1 parent 6aa6f75 commit d100d1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions blog/sl/re.pl
Expand Up @@ -32,6 +32,7 @@ sub usage {
usage() if not $getopt_result;

my $string = join q{}, <>;
chomp $string;
my $tchrist_regex = '(\\((?:[^()]++|(?-1))*+\\))';
my @re_results = ($string =~ m/$tchrist_regex/msxg);
say join "\n", map { (length $_) . ': ' . substr $_, 0, 40 } @re_results;
Expand Down
20 changes: 13 additions & 7 deletions blog/sl/sl.pl
Expand Up @@ -34,6 +34,7 @@ sub usage {
usage() if not $getopt_result;

my $string = join q{}, <>;
chomp $string;

my $grammar = Marpa::R2::Grammar->new(
{ start => 'start',
Expand Down Expand Up @@ -72,14 +73,18 @@ sub My_Error::last_completed_range {
# Initialize to one past the end, so we can tell if there were no hits
my $first_origin = $latest_earley_set + 1;
EARLEY_SET: while ( $earley_set >= 0 ) {
my $report_items = $recce->progress($earley_set);
ITEM: for my $report_item ( @{$report_items} ) {
my ( $rule_id, $dot_position, $origin ) = @{$report_item};

$recce->progress_report_start($latest_earley_set);
ITEM: while (1) {
my ( $rule_id, $dot_position, $origin ) = $recce->progress_item();
last ITEM if not defined $rule_id;

next ITEM if $dot_position != -1;
next ITEM if not scalar grep { $_ == $rule_id } @sought_rules;
next ITEM if $origin >= $first_origin;
$first_origin = $origin;
} ## end ITEM: for my $report_item ( @{$report_items} )
} ## end ITEM: while (1)
$recce->progress_report_finish();
last EARLEY_SET if $first_origin <= $latest_earley_set;
$earley_set--;
} ## end EARLEY_SET: while ( $earley_set >= 0 )
Expand All @@ -89,6 +94,7 @@ sub My_Error::last_completed_range {

my $thin_grammar = $grammar->thin();
my $recce = Marpa::R2::Thin::R->new($thin_grammar);
$recce->start_input();

# A quasi-object, for internal use only
my $self = bless {
Expand Down Expand Up @@ -122,9 +128,9 @@ sub My_Error::last_completed_range {

$recce->input_string_set($string);
my $event_count = $recce->input_string_read();
if ( $event_count < 0 ) {
die "Error in input_string_read: $event_count";
}
# if ( $event_count < 0 ) {
# die "Error in input_string_read: $event_count";
# }

# Given a string, an earley set to position mapping,
# and two earley sets, return the slice of the string
Expand Down

0 comments on commit d100d1b

Please sign in to comment.