UPDATE 1: It looks like changing digit().plus()
to word().plus()
works. Does that seem right?
Petitparser has proven to be very powerful! I have the following flutter/dart code:
testString = '((S|71|L || S|70|L || S|69|L || S|72|L) && (F|54|L || F|52|L || H|5|L))';
final builder = ExpressionBuilder();
final primitive = (uppercase() & char('|') & digit().plus() & char('|') & uppercase()).flatten().trim();
builder.group().primitive(primitive);
builder.group()
.wrapper(char('(').trim(), char(')').trim(), (l, v, r) => v);
builder.group()
..left(string('&&').trim(), (a, op, b) => ['&&', a, b])
..left(string('||').trim(), (a, op, b) => ['||', a, b]);
final parser = builder.build().end();
final result = parser.parse(testString);
This works perfectly. However, when I change the testString slightly to the following (note the word test instead of the number 5), I get the error in the title uppercase letter expected at 1:1
:
testString = '((S|71|L || S|70|L || S|69|L || S|72|L) && (F|54|L || F|52|L || H|test|L))';
I can't seem to figure out what it thinks should be an uppercase letter, or how to change the parser. I was thinking maybe it is something with the digit().plus()
, since that's the part of my primitive that I'm changing, but I tried changing that to any().plus()
and it shows the same error.
Can anyone help? Thanks!