1
0
forked from VimPlug/jedi

Starting with Python 3.4 from is not a token that always is a "new" statement.

This commit is contained in:
Dave Halter
2015-12-26 02:47:22 +01:00
parent eb2e41f771
commit ab5d0ed72b
3 changed files with 7 additions and 4 deletions

View File

@@ -165,7 +165,8 @@ class Parser(object):
typ = token.opmap[value]
yield typ, value, prefix, start_pos
def error_recovery(self, *args, **kwargs):
def error_recovery(self, grammar, stack, typ, value, start_pos, prefix,
add_token_callback):
raise ParseError
def convert_node(self, grammar, type, children):
@@ -207,7 +208,7 @@ class Parser(object):
return new_node
def convert_leaf(self, grammar, type, value, prefix, start_pos):
#print('leaf', value, pytree.type_repr(type))
#print('leaf', repr(value), token.tok_ntype)
if type == tokenize.NAME:
if value in grammar.keywords:
if value in ('def', 'class', 'lambda'):
@@ -350,7 +351,7 @@ class ParserWithRecovery(Parser):
# Otherwise the parser will get into trouble and DEDENT too early.
self._omit_dedent_list.append(self._indent_counter)
if value in ('import', 'from', 'class', 'def', 'try', 'while', 'return'):
if value in ('import', 'class', 'def', 'try', 'while', 'return'):
# Those can always be new statements.
add_token_callback(typ, value, prefix, start_pos)
elif typ == DEDENT and symbol == 'suite':

View File

@@ -143,7 +143,7 @@ del _compile
tabsize = 8
ALWAYS_BREAK_TOKENS = (';', 'import', 'from', 'class', 'def', 'try', 'except',
ALWAYS_BREAK_TOKENS = (';', 'import', 'class', 'def', 'try', 'except',
'finally', 'while', 'return')

View File

@@ -1319,6 +1319,8 @@ class ReturnStmt(KeywordStatement):
class YieldExpr(BaseNode):
__slots__ = ()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def type(self):
return 'yield_expr'