diff --git a/lex3.py b/lex3.py index 6056fac..ed3a32c 100755 --- a/lex3.py +++ b/lex3.py @@ -253,12 +253,13 @@ class RegionRule(Rule): # ok, so now loop over all the tokens in the current grammar, until # the stop-token (if any) is found, and return each result as we get # it. + tok = None for tok in self._lex(lexer, toresume, tokname, stopre, grammar): yield tok # ok, so now either we found the stop-token, and have a new parent # for future tokens (if any), or we are done. - if tok.name == tokname: + if tok is not None and tok.name == tokname: toresume = [tok] matchd.update(tok.matchd) else: