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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -