python - When using setResultsName with listAllMatches true, some matched items are nested -
based on grammar:
from pyparsing import * g = quotedstring.setparseaction( removequotes ) eg = suppress('-') + quotedstring.setparseaction( removequotes ) choice = or( [ g.setresultsname("out",listallmatches=true), eg.setresultsname("in",listallmatches=true) ] ) grammar = zeroormore( choice ) + suppress(restofline) = world.parsestring( ' "ali" -"baba" "holy cow" -"smoking beaute" ' ) print a.dump()
i have discovered tokens satisfy eg
nonterminal wrapped in list. difference g
has leading `suppress('-')'.
['ali', 'baba', 'holy cow', 'smoking beaute'] - in: [['baba'], ['smoking beaute']] - out: ['ali', 'holy cow']
how make them behave same ? want achieve result below:
['ali', 'baba', 'holy cow', 'smoking beaute'] - in: ['baba', 'smoking beaute'] - out: ['ali', 'holy cow']
it's been while since i've looked @ issue - problem and's return tokens lists, if contain single value.
here ungrouper can clear you, i'll include in next pyparsing release:
ungroup = lambda expr : tokenconverter(expr).setparseaction(lambda t:t[0]) eg = ungroup(suppress('-') + quotedstring.setparseaction( removequotes ))
with test code, these results:
['ali', 'baba', 'holy cow', 'smoking beaute'] - in: ['baba', 'smoking beaute'] - out: ['ali', 'holy cow']
Comments
Post a Comment