Closed NobbZ closed 2 years ago
You are right, in the example above you do not need ref0
, because there are no cycles in your grammar.
Consider the following example that parses balanced parenthesis:
class ParensGrammar extends GrammarDefinition {
Parser start() => char('(') & ref0(start) & char(')')
| epsilon();
}
If you replaced ref0(start)
with start()
you would end up with an infinite recursion when building the grammar. The ref0
functionality breaks such cycles apart and makes sure that repeatedly referenced parsers are only instantiated once (see documentation).
Hello!
I'm currently checking out dart and petitparser as an alternative to a rust based parser I currently have.
So far I really love it, and the declared parsers reads much cleaner.
Though I am wondering how
refX
is relevant?It seems that both
date
anddateRef
in the following definition just work…Omitting the
refX
makes the code much cleaner, though I fear to miss something. In case I am missing something important, I think it would be nice to add about the relevancy to the documentation.