Closed bvssvni closed 8 years ago
There are 3 states, one when the rule has not been called, one when it is called, and one when it is terminated. The node gets terminated when it is called with the same TokenizerState
twice.
pub enum Terminate {
None,
Some(usize),
LastChance(usize),
}
The terminated state the LastChance
state, where it has to find some other rule that makes progress, or else it will fail. It can not call itself because that would be giving itself another chance.
This will prevent infinite recursion, but won't allow left recursion because it can not backtrack once a select rule matches. It builds chains in the right argument, but often you want to build chains in the left argument.
Will have to wait for later.
If a node is enters itself without advancing, it risks entering an infinite recursion loop. Could detect this and terminate the self rule. This will make the parser try other rules as alternatives.
For example:
Reading:
Call tree:
This could make it easier to write advanced grammars.