This could be an opportunity for someone to write an event tutorial,
like the one Paul was talking about. Marpa will handle the Unicode nicely.
As I see the solution in outline, if each card is a lexeme, you define
an "after lexeme" named event which updates a hash, similarly to what is
done in the Perl 6 example's "card" token routine. (If cards are higher
level than lexemes, you use a "completed" event instead.) If checking
the hash indicates a card is a duplicate, you don't need to read on --
you stop and report failure. If you read the end of input without
failure, you go on to call $slr->value() to obtain the value.
Note the conclusion points out a major advantage of Marpa's approach.
Marpa's events are called once and only once, when an instance of that
event occurs. So what, you say? Well, if your parser gets its power
via backtracking, it means you will have a very hard time predicting
when and how many times the rule and symbol routines are called. Marpa
never backtracks, and each rule and symbol instance is encountered and
dealt with once and only once.
If the Perl 6 grammar in the post were expanded, and started to require
backtracking, it would fail in mystifying ways. This could be prevented
by having the routines track the number of times they are called for
each instance of their rule or symbol, in each Perl 6 parse, and
dividing their logic into that part which should be executed repeatedly,
at each encounter, and a part which should be executed only once, the
first time that a rule or symbol instance is encountered. But what
happens if on the first encounter you execute the once-only logic, but
then backtracking determines that that particular parse path will not be
used? Hmmmm.
In my very biased opinion, I think a Marpa solution might look
relatively simple and elegant.
Happy hacking, jeffrey
On 12/18/2013 01:53 PM, Jakub Narębski wrote:
I have just read article on parsing on Perl 6 Advent 2013 Calendar
series,
"Day 18 – A Grammar with Duplicate checking"
https://perl6advent.wordpress.com/2013/12/18/day-18-a-grammar-with-duplicate-checking/
I wonder: how such grammar can be implemented in Marpa's SLIF parser
(or perhaps there exists Perl6 Grammar rules parser for Marpa?), and if
duplicate detection must be put in procedural code.
--
Jakub Narębski
--
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 marpa-parser+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
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 marpa-parser+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.