Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top