Both cases should print the same statement but they print similar statements but the outpur of this is:
['[', '::1', ']'][
The answer to this is simple, opt1.saveAsList == True but opt2.saveAsList == False, so when building the ParseResults after the element has been match, only the first element of ipv6 is selected given a name.
I know that if i use Combine(ipv6) when declaring opt2 and it should be enought, i also know that i could alays change MatchFirst.saveAsList, but seems like a extra step for something that seems intuitive from the syntax, match ipv4 or ipv6 and then name that result as IP.
I cna think of 2 solutions for this:
1) is to overwrrite the setResultsName in MatchFirst to a simpler version of map(lambda e: e.setResultsName(name), self.exprs).
2) in parseImpl after ret = e._parse( instring, loc, doActions ) do self.saveAsList = e.saveAsList
what do you guys think?
Last edit: Alvaro Leiva 2017-07-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think this is a bug, but it may be intended behaivure, just dont seems right o me (by the way love pyparsing!!!).
concider
opt1
andopt2
, defined as follow:Both cases should print the same statement but they print similar statements but the outpur of this is:
The answer to this is simple,
opt1.saveAsList == True
butopt2.saveAsList == False
, so when building theParseResults
after the element has been match, only the first element of ipv6 is selected given a name.I know that if i use
Combine(ipv6)
when declaringopt2
and it should be enought, i also know that i could alays changeMatchFirst.saveAsList
, but seems like a extra step for something that seems intuitive from the syntax, matchipv4
oripv6
and then name that result as IP.I cna think of 2 solutions for this:
1) is to overwrrite the
setResultsName
inMatchFirst
to a simpler version ofmap(lambda e: e.setResultsName(name), self.exprs)
.2) in
parseImpl
afterret = e._parse( instring, loc, doActions )
doself.saveAsList = e.saveAsList
what do you guys think?
Last edit: Alvaro Leiva 2017-07-01
this is my idea https://github.com/aleivag/pyparsing/pull/1/commits/6e3e704f46ef2b7b0126380c8d0957a5188a087d