#!/usr/bin/env perl use warnings; use strict; use Data::Dumper; use Marpa::R2; my $rules = <<'END_OF_GRAMMAR'; lexeme default = latm => 1 :default ::= action => [values] ::= (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 "\nPARSING: $_\n"; my $recce = Marpa::R2::Scanless::R->new({ grammar => $grammar, }); my $value_ref = $grammar->parse( \$_); print Dumper $$value_ref; } } __OUTPUT__ PARSING: add 192.0.2.1 $VAR1 = [ [ 'add' ], [ [ '192.0.2.1' ] ] ]; PARSING: add www.example.org $VAR1 = [ [ 'add' ], [ [ 'www.example.org' ] ] ]; PARSING: remove 192.0.2.2 $VAR1 = [ [ 'remove' ], [ [ '192.0.2.2' ] ] ];