Skip to content

Instantly share code, notes, and snippets.

@rns
Created September 5, 2014 08:52
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/17faef77b8d3468fb7fe to your computer and use it in GitHub Desktop.
Save rns/17faef77b8d3468fb7fe to your computer and use it in GitHub Desktop.
use 5.018;
use strictures;
use Marpa::R2 qw();
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,
});
print $grammar->show_rules;
print $grammar->show_symbols;
my $parser = Marpa::R2::Scanless::R->new({
grammar => $grammar,
trace_terminals => 1,
trace_values => 1,
});
$parser->read(\qq("foo\N{REVERSE SOLIDUS}"bar"));
use YAML; say Dump ${$parser->value};
@rns
Copy link
Author

rns commented Sep 5, 2014

Setting trace_terminals option
Setting trace_values option
Lexer "L0" accepted lexeme L1c1 e1: '"'; value="""
Lexer "L0" accepted lexeme L1c2 e2: stringbodychar; value="f"
Lexer "L0" accepted lexeme L1c3 e3: stringbodychar; value="o"
Lexer "L0" accepted lexeme L1c4 e4: stringbodychar; value="o"
Lexer "L0" accepted lexeme L1c5-6 e5: stringbodychar; value="\""
Lexer "L0" accepted lexeme L1c7 e6: stringbodychar; value="b"
Lexer "L0" accepted lexeme L1c8 e7: stringbodychar; value="a"
Lexer "L0" accepted lexeme L1c9 e8: stringbodychar; value="r"
Lexer "L0" accepted lexeme L1c10 e9: '"'; value="""
G1 R0 escapedstring ::= '"' stringbody '"'
G1 R1 stringbody ::= stringbodychar *
G1 R2 :start ::= escapedstring
G1 S0 :start -- Internal G1 start symbol
G1 S1 '"' -- Internal lexical symbol for "'"'"
G1 S2 '"' -- Internal lexical symbol for "'"'"
G1 S3 escapedstring
G1 S4 stringbody
G1 S5 stringbodychar
--- !!perl/array:Quot::escapedstring
- '"'
- !!perl/array:Quot::stringbody
  - !!perl/array:Quot::stringbodychar
    - f
  - !!perl/array:Quot::stringbodychar
    - o
  - !!perl/array:Quot::stringbodychar
    - o
  - !!perl/array:Quot::stringbodychar
    - \"
  - !!perl/array:Quot::stringbodychar
    - b
  - !!perl/array:Quot::stringbodychar
    - a
  - !!perl/array:Quot::stringbodychar
    - r
- '"'

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