#!/usr/bin/env perl use warnings; use strict; use Data::Dumper; use Term::ANSIColor qw(:constants); use Marpa::R2; my $rules = <<'END_OF_GRAMMAR'; lexeme default = latm => 1 :default ::= action => [name,values] :start ::= ::= (SP) ::= 'add' | 'remove' ::= NUMBER ('.') NUMBER ('.') NUMBER ('.') NUMBER ::= NAME ::= | SP ~ [\s]+ NAME ~ [\S]+ NUMBER ~ [\d]+ END_OF_GRAMMAR my $input = <<'END_OF_INPUT'; add 192.0.2.1 add www.example.org remove 192.0.2.2 END_OF_INPUT my $grammar = Marpa::R2::Scanless::G->new({source => \$rules}); for (split /^/m, $input) { chomp; if (length $_) { print "\n\n$_\n"; my $recce = Marpa::R2::Scanless::R->new({ grammar => $grammar, ranking_method => 'rule' }); eval { $recce->read(\$_ ) }; print ($@ ? (RED . "$@\n") : GREEN); print $recce->show_progress(), "\n"; print Dumper($recce->value), "\n\n", RESET; } } #### ::= | ::= || ::= | ::= || ::= rank => 2 | rank => 1 ::= rank => 1 | rank => 2 ::= rank => 1 ::= rank => 2 ::= rank => 1 ::= rank => 2