You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @renggli , here's an issue I'm struggling with. There's a certain set of repeated patterns in which I want to attempt to detect a stricter subset first, and then fall back to a more generic one. Let's say I want to first detect a string of one or more uppercase A s or otherwise fall back to a string of case-insensitive as, e.g.
final uppercase =char('A').plus().map((_) =>'success');
final anycase =charIgnoringCase('A').plus().map((_) =>'fallback');
final parser = [uppercase, anycase].toChoiceParser().end();
print(parser.parse('AAAA')); // "success", as expectedprint(parser.parse('aaaAAaaa')); // "fallback", as expectedprint(parser.parse('AAaaaA')); // I expect "fallback", but getting "Failure[1:3]: end of input expected"
On the last print() I want to get a "fallback" as well. What's the right way to achieve this?
The text was updated successfully, but these errors were encountered:
You get this behavior in your last example because your uppercase parser succeeds consuming the two first uppercase A and the choice picks this result as a success.
In your example you can fix this by pulling up the .end() predicate into the choice:
final uppercase =char('A').plus().map((_) =>'success');
final anycase =charIgnoringCase('A').plus().map((_) =>'fallback');
final parser = [uppercase.end(), anycase.end()].toChoiceParser();
In a more general case you can say that uppercase is not followed by an anycase-character, i.e. something along the lines of:
final uppercase =char('A').plus().map((_) =>'success');
final anycase =charIgnoringCase('A').plus().map((_) =>'fallback');
final parser = [uppercase.skip(after:charIgnoringCase('A').not()), anycase].toChoiceParser().end();
Hi @renggli , here's an issue I'm struggling with. There's a certain set of repeated patterns in which I want to attempt to detect a stricter subset first, and then fall back to a more generic one. Let's say I want to first detect a string of one or more uppercase
A
s or otherwise fall back to a string of case-insensitivea
s, e.g.On the last
print()
I want to get a "fallback" as well. What's the right way to achieve this?The text was updated successfully, but these errors were encountered: