Reputation: 251
I have a very simple parser to implement boolean functionality, where I have added classes as parseAction for different operations.
parseExpr = pp.operatorPrecedence(term,
[
(not_, 1, pp.opAssoc.RIGHT, ClassNotOperation),
(pp.Optional(and_, default="AND"), 2, pp.opAssoc.LEFT, ClassAndOperation),
(or_, 2, pp.opAssoc.LEFT, ClassOrOperation),
])
This helps me parse following in the correct order
(A or B) and C
But, is there any way in which I can attach parseActions to parentheses blocks, if I want to add some operation on the block level?
Upvotes: 3
Views: 748
Reputation: 63762
Not using the standard API. If you want to do a special version of operatorPrecedence
(now renamed to infixNotation
), copy that routine out of the pyparsing Python code into your local script, and make whatever modifications you want.
Upvotes: 3