invalid.py test changes. Error recovery will be different from the old one.

This commit is contained in:
Dave Halter
2014-11-28 21:58:44 +01:00
parent 2c684906e3
commit 43c01afcfc
2 changed files with 26 additions and 14 deletions

View File

@@ -215,7 +215,7 @@ class Parser(object):
if symbol in ('file_input', 'suite'): if symbol in ('file_input', 'suite'):
break break
# No success finding a transition # No success finding a transition
print('err', tokenize.tok_name[typ], repr(value), start_pos, len(stack), index) #print('err', tokenize.tok_name[typ], repr(value), start_pos, len(stack), index)
self._stack_removal(grammar, stack, index + 1, value, start_pos) self._stack_removal(grammar, stack, index + 1, value, start_pos)
# Those can always be new statements. # Those can always be new statements.
if value in ('import', 'from', 'class', 'def', 'try', 'while', 'return'): if value in ('import', 'from', 'class', 'def', 'try', 'while', 'return'):
@@ -223,6 +223,7 @@ class Parser(object):
elif typ == tokenize.DEDENT: elif typ == tokenize.DEDENT:
if symbol == 'suite': if symbol == 'suite':
if len(nodes) > 2: if len(nodes) > 2:
# Finish the suite.
add_token_callback(typ, value, prefix, start_pos) add_token_callback(typ, value, prefix, start_pos)
else: else:
# If a function or anything else contains a suite that is # If a function or anything else contains a suite that is
@@ -250,6 +251,7 @@ class Parser(object):
if found: if found:
symbol = grammar.number2symbol[typ] symbol = grammar.number2symbol[typ]
failed_stack.append((symbol, nodes)) failed_stack.append((symbol, nodes))
if failed_stack:
err = ErrorStatement(failed_stack, value, start_pos) err = ErrorStatement(failed_stack, value, start_pos)
self.error_statement_stacks.append(err) self.error_statement_stacks.append(err)

View File

@@ -10,7 +10,7 @@ there should never be any errors.
##? 5 ##? 5
's'() 's'()
#? ['upper'] #? []
str()).upper str()).upper
# ----------------- # -----------------
@@ -19,16 +19,24 @@ str()).upper
def asdf(a or b): # multiple param names def asdf(a or b): # multiple param names
return a return a
#? int() #?
asdf(2) asdf(2)
asdf = ''
from a import (b from a import (b
def blub(): def blub():
return 0 return 0
def openbrace(): def wrong_indents():
asdf = 3 asdf = 3
asdf asdf
asdf( asdf(
# doesn't work because of the indent issues.
#? str()
asdf
def openbrace():
asdf = 3
asdf(
#? int() #? int()
asdf asdf
return 1 return 1
@@ -58,7 +66,7 @@ normalfunc()
# dots in param # dots in param
def f(seq1...=None): def f(seq1...=None):
return seq1 return seq1
#? int() #?
f(1) f(1)
@ @
@@ -97,13 +105,15 @@ try:
"" ""
# wrong ternary expression # wrong ternary expression
a = ''
a = 1 if a = 1 if
#? int() #? str()
a a
# No completions for for loops without the right syntax
for for_local in : for for_local in :
for_local for_local
#? ['for_local'] #? []
for_local for_local
#? #?
for_local for_local
@@ -122,7 +132,7 @@ a3 = [for xyz in]
a3[0] a3[0]
a3 = [a4 for in 'b'] a3 = [a4 for in 'b']
#? str() #?
a3[0] a3[0]
a3 = [a4 for a in for x in y] a3 = [a4 for a in for x in y]
@@ -140,7 +150,7 @@ def break(): pass
#? int() #? int()
a[0] a[0]
#? ['real'] #? []
int()).real int()).real
# ----------------- # -----------------
@@ -165,14 +175,14 @@ import datetime as
call = '' call = ''
invalid = .call invalid = .call
#? str() #?
invalid invalid
invalid = call?.call invalid = call?.call
#? str() #?
invalid invalid
# comma # comma
invalid = ,call invalid = ,call
#? str() #?
invalid invalid