After some further testing, I still do not see the value being updated in the case of the partial (but apparently successful) parse. I have added the :default rule you suggest above to two cases. Example 1 has been modified to match all tokens in the grammar( '12' and '3' ). It does return the expected 'name, value' structure. However, Example 2 retains the original string that only matches the first token ('12'). If the parse was successful, I would expect at least the matched tokens to appear in the value data, but it does not appear to exist. I have taken the time to read through the read and value documentation you linked above, but this information does not seem to explain the results I see here (or at least I'm not making sense of it).

use strict; use warnings; use Marpa::R2; use Data::Dumper; # Example 1 { my $g_str = <<'END_GRAMMAR'; :default ::= action => [name, value] :start ::= data data ::= '12' '3' END_GRAMMAR my $g_obj = Marpa::R2::Scanless::G->new({ source => \$g_str }); my $p_obj = Marpa::R2::Scanless::R->new({ grammar => $g_obj, trace_values => 1, trace_terminals => 1 }); my $s = '123'; $p_obj->read( \$s ); print "EXAMPLE 1 VALUE:".Dumper($p_obj->value)."\n"; } # Example 2 { my $g_str = <<'END_GRAMMAR'; :default ::= action => [name, value] :start ::= data data ::= '12' '3' END_GRAMMAR my $g_obj = Marpa::R2::Scanless::G->new({ source => \$g_str }); my $p_obj = Marpa::R2::Scanless::R->new({ grammar => $g_obj, trace_values => 1, trace_terminals => 1 }); my $s = '12'; $p_obj->read( \$s ); print "EXAMPLE 2 VALUE:".Dumper($p_obj->value)."\n"; }

Output:

Setting trace_terminals option Setting trace_values option Lexer "L0" accepted lexeme L1c1-2: '12'; value="12" Lexer "L0" accepted lexeme L1c3: '3'; value="3" EXAMPLE 1 VALUE:$VAR1 = \[ 'data', '12', '3' ]; Setting trace_terminals option Setting trace_values option Lexer "L0" accepted lexeme L1c1-2: '12'; value="12" EXAMPLE 2 VALUE:$VAR1 = undef;

In example 2, given there is now a :default rule for returning match data from a structural rule, and that the parse was successful, why is there no output from value?

My guess is that since the 'data' token requires both '12' and '3' to match, 'data' was not successfully matched. This means there is no returned value for the token, resulting in an empty value data structure. But this sounds an awful lot like a grammar parse failure that should result in a ->read failure.

EDIT: As it turns out, I am making the faulty assumption that because the read method did not throw an error, the parse was successful. This is not necessarily true. See my post above Re^3: Marpa -- Partial grammar match does not result in failure


In reply to Re^2: Marpa -- Partial grammar match does not result in failure by tj_thompson
in thread Marpa -- Partial grammar match does not result in failure by tj_thompson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.