Skip to content

Instantly share code, notes, and snippets.

@rns
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rns/8e5df459febbcd03a909 to your computer and use it in GitHub Desktop.
Save rns/8e5df459febbcd03a909 to your computer and use it in GitHub Desktop.
use 5.018;
use strictures;
use Marpa::R2 qw();
use DDS;
my $source = <<'END';
:default ::=
action => [values]
bless => ::lhs
lexeme default =
action => [ value ]
bless => ::name
latm => 1
:start ::= escapedstring
escapedstring ::= '"' stringbody '"'
stringbody ::= stringbodychar*
stringbodychar ~ [^\\"] | escapedquote
escapedquote ~ '\"'
END
my $grammar = Marpa::R2::Scanless::G->new({
bless_package => 'Quot',
source => \$source,
});
for my $in (
qq("foo\N{REVERSE SOLIDUS}"bar"),
q("foo\N{REVERSE SOLIDUS}"bar"),
qq("foo\"bar"),
q("foo\"bar"),
){
say "\nInput: ", $in;
my $parser = Marpa::R2::Scanless::R->new({
grammar => $grammar,
});
eval {
$parser->read( \$in );
};
if ($@){
say "Parse failed!"
}
else{
DumpLex ${$parser->value};
}
}
@rns
Copy link
Author

rns commented Sep 5, 2014

Input: "foo\"bar"
$Quot_escapedstring1 = bless( [
                         '"',
                         bless( [
                           bless( [ 'f' ], 'Quot::stringbodychar' ),
                           bless( [ 'o' ], 'Quot::stringbodychar' ),
                           bless( [ 'o' ], 'Quot::stringbodychar' ),
                           bless( [ '\\"' ], 'Quot::stringbodychar' ),
                           bless( [ 'b' ], 'Quot::stringbodychar' ),
                           bless( [ 'a' ], 'Quot::stringbodychar' ),
                           bless( [ 'r' ], 'Quot::stringbodychar' )
                         ], 'Quot::stringbody' ),
                         '"'
                       ], 'Quot::escapedstring' );

Input: "foo\N{REVERSE SOLIDUS}"bar"
Parse failed!

Input: "foo"bar"
Parse failed!

Input: "foo\"bar"
$Quot_escapedstring1 = bless( [
                         '"',
                         bless( [
                           bless( [ 'f' ], 'Quot::stringbodychar' ),
                           bless( [ 'o' ], 'Quot::stringbodychar' ),
                           bless( [ 'o' ], 'Quot::stringbodychar' ),
                           bless( [ '\\"' ], 'Quot::stringbodychar' ),
                           bless( [ 'b' ], 'Quot::stringbodychar' ),
                           bless( [ 'a' ], 'Quot::stringbodychar' ),
                           bless( [ 'r' ], 'Quot::stringbodychar' )
                         ], 'Quot::stringbody' ),
                         '"'
                       ], 'Quot::escapedstring' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment