pub enum EmptyLoop {
Thompson,
Perl,
}Expand description
Which reading a repetition takes when its body can match without consuming a token.
Allowing an empty iteration to repeat leaves a greedy star with no most-preferred derivation at all, so every engine removes something to make an answer exist, and the two families remove different things. The difference is visible only where the body’s highest-priority alternation branch is nullable and a lower-priority one consumes; reverse those two and the readings agree.
This is a property of the whole pattern rather than of one node. A pattern
names it with a leading (?empty:perl) or (?empty:thompson), and
crate::parser::parse_with_empty_loop hands it back beside the tree;
the tree itself does not carry it, so no consumer can forget to unwrap it
and read the wrong one.
Variants§
Thompson
The crate’s reading, and the default. A thread whose body matched empty returns to a state it already stood at, and a simulation that carries one thread per state drops it, so the branch that consumed wins.
Perl
The backtracking reading. The empty iteration is taken and the loop then breaks, so the branch that matched empty is on the path and the match ends earlier.