Skip to content

Commit 4636249

Browse files
numberpicosminbasca
authored andcommitted
Fix source section off-by-one error, fix source sections for leaf nodes
1 parent 7951852 commit 4636249

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/PythonBaseTreeTranslator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public Object visitChildren(RuleNode node) {
162162
}
163163

164164
protected void deriveSourceSection(RuleNode node, Object r) {
165-
if (r instanceof PNode) {
165+
if (r instanceof PNode && ((PNode) r).getSourceSection() == null) {
166166
SourceSection derivedSection = deriveSourceSection(node);
167167
if (derivedSection != null) {
168168
((PNode) r).assignSourceSection(derivedSection);
@@ -186,7 +186,7 @@ private SourceSection deriveSourceSection(RuleNode node) {
186186
} else if (node instanceof ParserRuleContext) {
187187
int start = ((ParserRuleContext) node).getStart().getStartIndex();
188188
int stop = ((ParserRuleContext) node).getStop().getStopIndex();
189-
return createSourceSection(start, stop - start);
189+
return createSourceSection(start, stop - start + 1);
190190
}
191191
return null;
192192
}

0 commit comments

Comments
 (0)