Fix a few issues caused by the refactoring.

This commit is contained in:
Dave Halter
2016-05-29 19:49:35 +02:00
parent feef45f4bb
commit daa68b66ad
8 changed files with 60 additions and 33 deletions

View File

@@ -113,11 +113,17 @@ class ErrorStatement(object):
of the stack at which time its parents don't yet exist..
"""
start_pos = self.start_pos
for c in root_node.children:
if c.start_pos < start_pos <= c.end_pos:
return self.set_parent(c)
try:
children = root_node.children
except AttributeError:
self.parent = root_node
else:
for c in children:
if c.start_pos < start_pos <= c.end_pos:
self.set_parent(c)
return
self.parent = root_node
self.parent = root_node
class ErrorToken(tree.LeafWithNewLines):
@@ -288,6 +294,10 @@ class Parser(object):
return pt.Number(self.position_modifier, value, start_pos, prefix)
elif type in (NEWLINE, ENDMARKER):
return pt.Whitespace(self.position_modifier, value, start_pos, prefix)
elif type == INDENT:
return pt.Indent(self.position_modifier, value, start_pos, prefix)
elif type == DEDENT:
return pt.Dedent(self.position_modifier, value, start_pos, prefix)
else:
return pt.Operator(self.position_modifier, value, start_pos, prefix)

View File

@@ -121,7 +121,8 @@ class PgenParser(object):
break
else:
# We never broke out -- EOF is too soon -- Unfinished statement.
self.error_recovery(self.grammar, self.stack, type_, value,
# TODO the arcs argument [] is not correctly defined.
self.error_recovery(self.grammar, self.stack, [], type_, value,
start_pos, prefix, self.addtoken)
# Add the ENDMARKER again.
if not self.addtoken(type_, value, prefix, start_pos):

View File

@@ -433,6 +433,16 @@ class String(Literal):
__slots__ = ()
class Indent(Leaf):
type = 'indent'
__slots__ = ()
class Dedent(Leaf):
type = 'indent'
__slots__ = ()
class Operator(Leaf):
type = 'operator'
__slots__ = ()