[jsinterp] Fixing TokenStrem pop, label statement, function body
This commit is contained in:
parent
f24cafea89
commit
a8a445f04c
@ -292,15 +292,12 @@ class JSInterpreter(object):
|
|||||||
raise ExtractorError('Unexpected sequence %s at %d' % (peek_value, peek_pos))
|
raise ExtractorError('Unexpected sequence %s at %d' % (peek_value, peek_pos))
|
||||||
else:
|
else:
|
||||||
token_stream.pop()
|
token_stream.pop()
|
||||||
# label
|
|
||||||
else:
|
else:
|
||||||
token_stream.chk_id()
|
token_id, token_value, token_pos = token_stream.peek(2)
|
||||||
token_id, label_name, token_pos = token_stream.pop()
|
if token_id is Token.COLON:
|
||||||
token_id, token_value, token_pos = token_stream.pop()
|
token_id, label_name, token_pos = token_stream.pop(2)
|
||||||
if token_id is not Token.COLON:
|
token_stream.chk_id(last=True)
|
||||||
raise ExtractorError('''Label statement missing ':' at %d''' % token_pos)
|
statement = (Token.LABEL, label_name, self._next_statement(token_stream, stack_top - 1))
|
||||||
|
|
||||||
statement = (Token.LABEL, label_name, self._next_statement(token_stream, stack_top - 1))
|
|
||||||
|
|
||||||
# expr
|
# expr
|
||||||
if statement is None:
|
if statement is None:
|
||||||
@ -520,11 +517,12 @@ class JSInterpreter(object):
|
|||||||
elif not is_expr:
|
elif not is_expr:
|
||||||
raise ExtractorError('Function declaration at %d is missing identifier' % token_pos)
|
raise ExtractorError('Function declaration at %d is missing identifier' % token_pos)
|
||||||
|
|
||||||
if token_id is Token.POPEN:
|
if token_id is not Token.POPEN:
|
||||||
open_pos = token_pos
|
|
||||||
else:
|
|
||||||
raise ExtractorError('Expected argument list at %d' % token_pos)
|
raise ExtractorError('Expected argument list at %d' % token_pos)
|
||||||
|
|
||||||
|
token_stream.pop()
|
||||||
|
open_pos = token_pos
|
||||||
|
|
||||||
args = []
|
args = []
|
||||||
while True:
|
while True:
|
||||||
token_id, token_value, token_pos = token_stream.peek()
|
token_id, token_value, token_pos = token_stream.peek()
|
||||||
|
@ -159,10 +159,12 @@ class TokenStream(object):
|
|||||||
return self.peeked[count - 1]
|
return self.peeked[count - 1]
|
||||||
|
|
||||||
def pop(self, count=1):
|
def pop(self, count=1):
|
||||||
if not self.peeked:
|
if count > len(self.peeked):
|
||||||
self.peek()
|
self.peek(count)
|
||||||
for _ in range(count):
|
self.flush()
|
||||||
self._last = self.peeked.pop()
|
else:
|
||||||
|
self._last = self.peeked[count - 1]
|
||||||
|
self.peeked = self.peeked[count:]
|
||||||
return self._last
|
return self._last
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user