Request for improvement of API
It'd be nice to have the following functions for Pairs to reduce the deep nesting:
find(Rule::SomeRule, max_level, min_level) -> Option<Pair>
find(&str, max_level, min_level) -> Option<Pair>
The former finds the first Pair that has the type Rule::SomeRule, while the latter does the same if the matched content = &str. max_level and min_level work to limit the search just like in Unix find command; Setting 0 means no limit.
In addition, it'd be nice to have the following stack functions:
IS_EMPTY: Match without progress if the stack is empty.
CONTAINS("abc") : Match without progress if the stack contains the string "abc".
The benefit of the stack functions is shown by the following example.
Int = @{ ASCII_DIGIT+ }
Word = @{ ASCII_ALPHA+ }
Defn = { COLON ~ Word ~ "=" ~ Int ~ SEMICOLON }
When the rule Int or Word is encountered, the program prints the value. When the rule Defn is encountered, the program simply stores the definition for future use. When we are parsing Defn, we don't want the Int and Word rules to fire and start printing. If there was an IS_EMPTY, we could've used it along with PUSH to stop the Int and Word from firing.