Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for improvement of API #605

Open
asarkar opened this issue Jun 23, 2022 · 0 comments
Open

Request for improvement of API #605

asarkar opened this issue Jun 23, 2022 · 0 comments

Comments

@asarkar
Copy link

asarkar commented Jun 23, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants