Simplify eof handling
This commit is contained in:
parent
cfafc2e235
commit
89a2057cac
@ -37,7 +37,6 @@ class ShellLexer:
|
|||||||
|
|
||||||
def __init__(self, s):
|
def __init__(self, s):
|
||||||
self.instream = StringIO(s)
|
self.instream = StringIO(s)
|
||||||
self.eof = None
|
|
||||||
self.whitespace = ' \t\r\n'
|
self.whitespace = ' \t\r\n'
|
||||||
self.quotes = '\'"'
|
self.quotes = '\'"'
|
||||||
self.escape = '\\'
|
self.escape = '\\'
|
||||||
@ -54,7 +53,7 @@ class ShellLexer:
|
|||||||
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 is None:
|
if self.state is None:
|
||||||
self.token = '' # past end of file
|
self.token = None # past end of file
|
||||||
break
|
break
|
||||||
elif self.state == ' ':
|
elif self.state == ' ':
|
||||||
if not nextchar:
|
if not nextchar:
|
||||||
@ -122,10 +121,7 @@ class ShellLexer:
|
|||||||
self.token = ''
|
self.token = ''
|
||||||
if not quoted and result == '':
|
if not quoted and result == '':
|
||||||
result = None
|
result = None
|
||||||
if result:
|
|
||||||
log.shlexer.debug("token={!r}".format(result))
|
log.shlexer.debug("token={!r}".format(result))
|
||||||
else:
|
|
||||||
log.shlexer.debug("token=EOF")
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
@ -133,7 +129,7 @@ class ShellLexer:
|
|||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
token = self.read_token()
|
token = self.read_token()
|
||||||
if token == self.eof:
|
if token is None:
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
return token
|
return token
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user