I am trying to parse a string data with nested curly braces, and I would like to remove the quotation marks from the parsed string elements, also ignore ",", "+" and empty string "" from the parsed list.
Here is what I have for the parser definition using pyparsing:
data = '{"url", {action1, action2}, "", class1 + class2}'
quotedString.setParseAction(removeQuotes)
parser = nestedExpr(opener="{", closer="}", ignoreExpr=(quotedString | Suppress(",") | Suppress("+")))
print(parser.parseString(data, parseAll=True)[0])
Here is the output:
['url', ['action1', 'action2'], '', 'class1', 'class2']
I would like to ignore the empty string '' during parsing and in the output, I tried adding Suppress(",") in ignoreExpr, but it seems the program goes into loop and give warning SyntaxWarning: null string passed
Also, is there a way to combine the Suppress() strings into a list instead of writing them one by one?
Thanks in advance.