python - acccumulate using pyparsing -
i have data can parsed using oneormore function pyparsing. like,
fun = oneormore( foo.setresultsname("foo") + bar.setresultsname("bar") ) where bar , foo 2 parsers.
the problem function everytime oneormore match foo , bar parsers in data stream, corresponding values associated keys "foo" , "bar" updated.but, how can accumulate matched values of foo , bar?
i'm trying implement many1 monadic parser in haskell, saving result of parsing foo , bar in algebraic data type, like
data foobar = foobar a many1 :: parsect s u m -> parsect s u m [a] many1 parserfoobar :: parsect s u m [foobar a] how can in python?
i'm not 100% sure understand you're asking, , rusty pyparsing, think group you.
from pyparsing import * text = 'abc123xyz456def789' foo = word(alphas) bar = word(nums) fun = oneormore(group(foo.setresultsname("foo") + bar.setresultsname("bar"))) results = fun.parsestring(text) #print foo print [r.foo r in results] #print bar print [r.bar r in results]
Comments
Post a Comment