[Pyparsing] setResultsName on a recursive element of grammar
Brought to you by:
ptmcg
From: Elizabeth M. <eli...@in...> - 2016-02-20 14:25:58
|
Hello, So I am trying to create a recursive grammar that specifies RFC1459-style IRC frames for a pet project. This is what I have so far: ---SNIP--- > command = Word(alphanums).setResultsName("command") > middle = Word(alphanums) # Middle parameter > end = Literal(":").suppress() # Last optional parameter > param = Forward() > param << Optional((middle + param) | end) > param = param.setResultsName("param", listAllMatches=True) > > line = command + param + stringEnd() Unfortunately, the result I get out of it is this: > l = line.parseString("COMMAND param1 param2 :param3") > print(l.param) >> ['param1'] It "works" when I do: > param = Group(param).setResultsName("param", listAllMatches=True) But then it nests everything: >> [['param1', 'param2', 'param last']] I'm not entirely sure what to do here, or if this is a bug? (or a bug in my grammar?) -- Elizabeth |