Created
September 5, 2014 04:48
-
-
Save rns/96647c9205db54e087a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use 5.010; | |
use strict; | |
use warnings; | |
use Marpa::R2; | |
use YAML; | |
my $g = Marpa::R2::Scanless::G->new( { | |
source => \(<<'END_OF_SOURCE'), | |
:default ::= action => [name, value] | |
lexeme default = action => [name, value] latm => 1 | |
S ::= quote text quote | |
text ::= in_quotes+ | |
in_quotes ::= non_quote | escaped_quote | |
quote ~ '"'; | |
non_quote ~ [^"\\]+ # " | |
escaped_quote ~ '\"' | |
:discard ~ whitespace | |
whitespace ~ [\s]+ | |
END_OF_SOURCE | |
} ); | |
my $input = <<EOI; | |
"before escaped quotes \\"in escaped quotes\\" after escaped quotes \\"again in escaped quotes\\" and some text again" | |
EOI | |
my $r = Marpa::R2::Scanless::R->new( { grammar => $g, trace_terminals => 1 } ); | |
eval {$r->read(\$input)} || die "\nParse failure, progress report is:\n" . $r->show_progress; | |
say Dump ${ $r->value }; |
Author
rns
commented
Sep 5, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment