How to validate boolean expression syntax using pyparsing?

后端 未结 1 367
粉色の甜心
粉色の甜心 2021-01-15 06:26

I\'m using the Pyparsing library to evaluate simple boolean queries like these ones:

  • (True AND True) OR False AND True
  • (True AND (True OR False OR Tru
相关标签:
1条回答
  • 2021-01-15 07:08

    Answer by @PaulMcGuire:

    Change boolExpr.parseString(t)[0] to boolExpr.parseString(t, parseAll=True)[0]. Pyparsing will not raise an exception if it can find a valid match in the leading part of the string, even if there is junk tacked on to the end. By adding parseAll=True, you tell pyparsing that the entire string must parse successfully.

    0 讨论(0)
提交回复
热议问题