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
base: master
Are you sure you want to change the base?
Conversation
…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.
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. |
There was a problem hiding this 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.
Implemented minor fixes to infix_math_parser.py based on comments by @ptmcg.
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. |
…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.