Merge pull request #1476 from renatahodovan/python-target-1472

Implement the fix of #1298 for Python targets.
This commit is contained in:
Terence Parr 2016-12-11 14:49:28 -08:00 committed by GitHub
commit 6a20919cb7
3 changed files with 37 additions and 1 deletions

View File

@ -112,7 +112,7 @@ public class ParseTreesDescriptors {
@Override
public boolean ignore(String targetName) {
return !targetName.equals("Java");
return !targetName.matches("Java|Python2|Python3");
}
}

View File

@ -46,6 +46,15 @@ class ParserRuleContext(RuleContext):
self.exception = None
#* COPY a ctx (I'm deliberately not using copy constructor)#/
#
# This is used in the generated parser code to flip a generic XContext
# node for rule X to a YContext for alt label Y. In that sense, it is
# not really a generic copy function.
#
# If we do an error sync() at start of a rule, we might add error nodes
# to the generic XContext so this function must copy those nodes to
# the YContext as well else they are lost!
#/
def copyFrom(self, ctx):
# from RuleContext
self.parentCtx = ctx.parentCtx
@ -54,6 +63,15 @@ class ParserRuleContext(RuleContext):
self.start = ctx.start
self.stop = ctx.stop
# copy any error nodes to alt label node
if ctx.children is not None:
self.children = []
# reset parent pointer for any error nodes
for child in ctx.children:
if isinstance(child, ErrorNodeImpl):
self.children.append(child)
child.parentCtx = self
# Double dispatch methods for listeners
def enterRule(self, listener):
pass

View File

@ -51,6 +51,15 @@ class ParserRuleContext(RuleContext):
self.exception = None
#* COPY a ctx (I'm deliberately not using copy constructor)#/
#
# This is used in the generated parser code to flip a generic XContext
# node for rule X to a YContext for alt label Y. In that sense, it is
# not really a generic copy function.
#
# If we do an error sync() at start of a rule, we might add error nodes
# to the generic XContext so this function must copy those nodes to
# the YContext as well else they are lost!
#/
def copyFrom(self, ctx:ParserRuleContext):
# from RuleContext
self.parentCtx = ctx.parentCtx
@ -59,6 +68,15 @@ class ParserRuleContext(RuleContext):
self.start = ctx.start
self.stop = ctx.stop
# copy any error nodes to alt label node
if ctx.children is not None:
self.children = []
# reset parent pointer for any error nodes
for child in ctx.children:
if isinstance(child, ErrorNodeImpl):
self.children.append(child)
child.parentCtx = self
# Double dispatch methods for listeners
def enterRule(self, listener:ParseTreeListener):
pass