#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; use Marpa::R2; Main( @ARGV ); exit( 0 ); sub Main { my $grammar_spec = get_grammar(); my $test_input = test_input(); my $grammar = Marpa::R2::Scanless::G->new({ bless_package => 'Ast', source => \$grammar_spec, }); my $recce = Marpa::R2::Scanless::R->new({ grammar => $grammar }); $recce->read(\$test_input); my $val = $recce->value; dd( $val ); } ## no definition means "Unproductive lexical symbols: " sub get_grammar { return q{ :default ::= action => [values] :start ::= Lines Lines ::= Line* Line ::= Words | Words | Words ::= * Word ::= | punctuationwordchars ::= | continuation ~ '\\' [\n] PosixPunct ~ [\N{U+0021}-\N{U+002F}\N{U+003A}-\N{U+0040}\N{U+005B}-\N{U+0060}\N{U+007B}-\N{U+007E}]+ wordchars ~ [\w]+ ~ [\n]+ :discard ~ ws ws ~ [ \f\r\t]+ } } sub test_input { #~ I can't seem to face up to the facts #~ I'm tense and nervous and I\ #~ Can't relax return q{ I can't sleep 'cause my bed's on fire Don't touch me I'm a real live wire a b c\ 1 2 3\ do re mi you and me girl } } __END__ \[ ["\n"], [ [ ["I"], ["can", ["'", "t"]], ["sleep", ["'", "cause"]], ["my"], ["bed", ["'", "s"]], ["on"], ["fire"], ], "\n", ], [ [ ["Don", ["'", "t"]], ["touch"], ["me"], ["I", ["'", "m"]], ["a"], ["real"], ["live"], ["wire"], ], "\n", ], [ [["a"], ["b"], ["c"]], "\\\n", [[[1], [2], [3]], "\\\n", [[["do"], ["re"], ["mi"]], "\n"]], ], [[["you"], ["and"], ["me"], ["girl"]], "\n"], ]