[Python-ideas] Yield-from example: A parser
Bruce Frederiksen
dangyogi at gmail.com
Wed Feb 18 02:29:00 CET 2009
Antoine Pitrou wrote:
> How about:
>
> def scanner(text):
> for m in pat.finditer(text):
> token = m.group(0)
> print "Feeding:", repr(token)
> yield token
> yield None # to signal EOF
>
> and:
>
> def parse_items(closing_tag = None):
> elems = []
> while 1:
> token = token_stream.next()
> if not token:
> break # EOF
> [etc.]
>
Or just:
def scanner(text):
for m in pat.finditer(text):
token = m.group(0)
print "Feeding:", repr(token)
yield token
and:
def parse_items(closing_tag = None):
elems = []
for token in token_stream:
[etc.]
-bruce frederiksen
More information about the Python-ideas
mailing list