I've been using parse when working on commonmark parser <https://github.com/rns/MarpaX-Languages-CommonMark-AST> and here is the how it turned out.
First, parse() does a great job when testing with unambiguous grammar and input — it throws an exception on ambiguity and that's what you want. However, when thing get more complex and I needed, e.g. just dump multiple parses, the recognizer is hidden behind the otherwise very useful parse() interface, and to do that _while still keeping the behaviour in unambiguous case_, I had to mimic parse()'s functionality, like this <https://github.com/rns/MarpaX-Languages-CommonMark-AST/blob/master/lib/MarpaX/Languages/CommonMark/AST.pm#L236> . I understand that it is by design, hence my suggestion is that in list context parse(), rather than throwing an exception, return its recognizer (probably after series_restart() so that it's ready to use), like this. my ($value, $recognizer) = $slg->parse( { input => \$input } ); Another, arguably better, option would be to return the abstract syntax forest parse() produces, e.g. my ($value, $asf) = $slg->parse( { input => \$input } ); This would require adding recognizer() method to Marpa::R2::ASF (grammar() is already there) . The full use case I have in mind: my ($value, $recognizer_or_asf) = $slg->parse( { input => \$input } ); # check for ambiguity if (not defined $value){ # use the recognizer or the asf to handle ambiguity # and find the required value # e.g. sort the parses or prune the ASF or the ASTs # ... } # process $value if needed # ... The case where exception is thrown on ambiguity continues as is: my $value = $slg->parse( { input => \$input } ); -- You received this message because you are subscribed to the Google Groups "marpa parser" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
