Use a for loop

This commit is contained in:
Florian Bruhin 2014-11-06 09:02:21 +01:00
parent 5fe04a6aec
commit 2b8d6c5dd7

View File

@ -34,7 +34,7 @@ class ShellLexer:
""" """
def __init__(self, s): def __init__(self, s):
self.iterator = iter(s) self.string = s
self.whitespace = ' \t\r' self.whitespace = ' \t\r'
self.quotes = '\'"' self.quotes = '\'"'
self.escape = '\\' self.escape = '\\'
@ -50,15 +50,7 @@ class ShellLexer:
def __iter__(self): def __iter__(self):
"""Read a raw token from the input stream.""" """Read a raw token from the input stream."""
self.reset() self.reset()
while True: for nextchar in self.string:
try:
nextchar = next(self.iterator)
except StopIteration:
if self.state in self.escape and not self.keep:
self.token += self.state
if self.token or self.quoted:
yield self.token
return
log.shlexer.vdebug("in state {!r} I see character: {!r}".format( log.shlexer.vdebug("in state {!r} I see character: {!r}".format(
self.state, nextchar)) self.state, nextchar))
if self.state == ' ': if self.state == ' ':
@ -120,6 +112,10 @@ class ShellLexer:
self.state = nextchar self.state = nextchar
else: else:
self.token += nextchar self.token += nextchar
if self.state in self.escape and not self.keep:
self.token += self.state
if self.token or self.quoted:
yield self.token
def split(s, keep=False): def split(s, keep=False):