I am using pyparsing.operatorprecedence to parse a notation request. The code
filterExpr = pp.quotedString.setParseAction(pp.removeQuotes) |\
pp.Word(pp.printables, excludeChars="()")
searchTerm = (~and_ + ~or_ + ~not_) + filterExpr
searchExpr = pp.operatorPrecedence(
searchTerm,
[
(not_, 1, pp.opAssoc.RIGHT, SearchNotOperation),
(pp.Optional(and_, default="AND"), 2, pp.opAssoc.LEFT, SearchAndOperation),
(or_, 2, pp.opAssoc.LEFT, SearchOrOperation),
])
This parses expressions such as "(foo bar) or baz", but does not work in the case of an edge where an empty string or empty brackets are indicated ((). How can I solve this problem?
source
share