4 ms·
Huh? Not sure I know what you mean, because something like the following trivially works? grammar LOL { rule TOP { <string> } rule string {
by Ultimatt 9y ago
Huh? Not sure I know what you mean, because something like the following trivially works?
grammar LOL {
rule TOP { <string> }
rule string { <[a..z]><string>? }
}
my @lulz = LOL.parse("abcdef");
say @lulz;
---
[「abcdef」
string => 「abcdef」
string => 「bcdef」
string => 「cdef」
string => 「def」
string => 「ef」
string => 「f」]
- grondilu 9y agoI didn't say recursion never works. I say most of the times, it doesn't. There is no alternation in the example you provide, for instance. Had you written it like this: grammar { rule TOP { <string> } rule string { <[a..z]> | <string><[a..z]> } } as inspired by the rule mentioned above in the ECMAscript reference, it would fail.
- zengargoyle 9y agoI'm probably off the mark a little bit.... but 'rule' implies that whitespace is really <.ws> (totally ignored white space matching thingy). '|' is the Longest-Match-First (different from Perl/PCRE/etc). LMF is not possible in the case where it is not a DFA... the implicit <.ws> that is there by using 'rule' and having a space might be your problem... :) TL;DR Don't forget that 'rule' does <.ws> magic. This may or may not actually be part of the problem... I have seen a similar sort of thing and only half understand the answer i got.. Check your implicit <.ws> and '|' LMF.
- grondilu 9y agoI had tried replacing 'rule' by 'token' and it did not change much.