#9 Ability to remove bracket parsing from operatorPrecedence

open
nobody
None
5
2008-10-29
2008-10-29
Eike Welk
No

Complex parsers might want to parse brackets "()" outside of operatorPrecedence. For these parsers it would be useful if operatorPrecedence would not parse brackets.

Possible use cases might be:
- Need to record the fact that brackets were parsed; or need to call a parse action when brackets are parsed.
- Parser that wants the correct parsing of the exponentiation operator. A hand written parser for exponentiation and unarry minus is needed in this case. Additionally a separate parser for brackets is needed.

Therefore I propose an additional keyword argument for operatorPrecedence "handleBrackets=True". It should remove the bracket parsing abilities from operatorPrecedence when it is set to false.

A patch for this feature is attached.

Discussion

  • Eike Welk

    Eike Welk - 2008-10-29

    File Added: diff_operator_precedence_whish.txt

     
  • Eike Welk

    Eike Welk - 2008-10-29

    The line:
    lastExpr = baseExpr | ( Suppress('(') + ret + Suppress(')') )
    needs to be indented more. This is somehow wrong in the diff.
    (It might be a consequence of calling "diff -b ....")

     
  • Paul McGuire

    Paul McGuire - 2008-11-14

    I've been puzzling over how to handle exponentiation and unary minus - the Python grammar cheats, and so similar cheating in pyparsing is not beneath me. :) But my attempts to date are not successful. Maybe this would be a good GHOP project (if Google holds that contest again this year).

    oP has really gotten to be quite a minefield of code, so I am reluctant to further parameterize it. If I get the -x**y**z issue resolved, will that obviate the need for this request?

    -- Paul