-
I want to parse LaTex code like After read the tutorial on README, I found support for format like I want to know if there is an appropriate way to handle this problem. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Please consider asking general questions like this on https://stackoverflow.com/questions/tagged/dart+petitparser That said, the following code parses your example: final arg = char('{') & digit() & char('}');
final frac = string('\\frac') & arg.star(); |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer I do tried some similar ways to parse it:
But none of them work in a more complex situation like |
Beta Was this translation helpful? Give feedback.
-
To deal with nested grammars you need to recursively call yourself: final frac = undefined();
final expr = frac | digit();
final arg = char('{') & expr & char('}');
frac.set(string('\\frac') & arg.star());
print(frac.parse('\\frac{\\frac{1}{2}}{3}'));
// ==> Success[1:22]: [\frac, [[{, [\frac, [[{, 1, }], [{, 2, }]]], }], [{, 3, }]]] This kind of recursive code is easier to write when using a GrammarDefinition. |
Beta Was this translation helpful? Give feedback.
To deal with nested grammars you need to recursively call yourself:
This kind of recursive code is easier to write when using a GrammarDefinition.