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

Added a new example showcasing a recursive parser for parsing advance… #549

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gialmisi
Copy link

@gialmisi gialmisi commented Mar 8, 2024

…d mathematical expressions in infix notation.

The parser supports binary, unary, and variadic operators that can be customized by modifying the class variables. It therefore goes way beyond any existing examples for artithmetic expression parsers. It also showcases how regex can be utilized to improve the performance of a parser written utilzing pyparsing.

I wrote this parser for another project, where it was needed. I could not find a ready-made parser for my purposes in the examples, or the web in general. Therefore, I am making this pull request in hopes it gets accepted and hopefully lessens the burden of some other future user, who might have a similar need for a parser as I did. I left comments in the code that I made for myself when learning the library. I believe they add to the example, and therefore left them there.

…d mathematical expressions in infix notation.

The parser supports binary, unary, and variadic operators that can be customized by modifying the class variables.
It therefore goes way beyond any existing examples for artithmetic expression parsers. It also
showcases how regex can be utilized to improve the performance of a parser written utilzing pyparsing.

I wrote this parser for another project, where it was needed. I could not find a ready-made parser for my purposes in the
examples, or the web in general. Therefore, I am making this pull request in hopes it gets accepted and hopefully lessens
the burden of some other future user, who might have a similar need for a parser as I did. I left comments in the code that I made
for myself when learning the library. I believe they add to the example, and therefore left them there.
@ptmcg
Copy link
Member

ptmcg commented Mar 9, 2024

Looking over your parser this weekend, thanks for submitting it. In the meantime, please look at the plusminus package (https://github.com/pyparsing/plusminus). This package might do much of what you want, plus add evaluation as well as parsing.

Copy link
Member

@ptmcg ptmcg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice example, glad to see others making use of infix_notation like this.

examples/infix_math_parser.py Outdated Show resolved Hide resolved
examples/infix_math_parser.py Outdated Show resolved Hide resolved
examples/infix_math_parser.py Outdated Show resolved Hide resolved
examples/infix_math_parser.py Outdated Show resolved Hide resolved
examples/infix_math_parser.py Outdated Show resolved Hide resolved
examples/infix_math_parser.py Outdated Show resolved Hide resolved
examples/infix_math_parser.py Show resolved Hide resolved
examples/infix_math_parser.py Outdated Show resolved Hide resolved
examples/infix_math_parser.py Outdated Show resolved Hide resolved
examples/infix_math_parser.py Outdated Show resolved Hide resolved
Implemented minor fixes to infix_math_parser.py based on comments by @ptmcg.
@gialmisi
Copy link
Author

Looking over your parser this weekend, thanks for submitting it. In the meantime, please look at the plusminus package (https://github.com/pyparsing/plusminus). This package might do much of what you want, plus add evaluation as well as parsing.

Thanks, I wish I had found this before, might have been useful!

As for the other comments, I have addressed them and updated the PR. I always appreciate someone going over code I have written and giving feedback, especially with this level of care. Thanks!

The diffs are somehow messed up in the PR. I should check my IDE settings. Sorry for this. I would be happy if this example is included in pyparsing, but if its contribution to the framework is not enough to warrant a pull, that is fine as well.

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

Successfully merging this pull request may close these issues.

None yet

2 participants