Skip to content
Permalink
Browse files
Fix position info for rootnode and highest block node in presence of …
…only BEGIN nodes
  • Loading branch information
enebo committed Dec 5, 2014
1 parent 8ef9a88 commit 3e4e4791add33bc704fb512c59da1180dad7a976
@@ -173,15 +173,20 @@ public Node newline_node(Node node, ISourcePosition position) {
return node instanceof NewlineNode ? node : new NewlineNode(position, node);
}

public Node addRootNode(Node topOfAST, ISourcePosition position) {
position = topOfAST != null ? topOfAST.getPosition() : position;

public Node addRootNode(Node topOfAST) {
if (result.getBeginNodes().isEmpty()) {
if (topOfAST == null) topOfAST = NilImplicitNode.NIL;
ISourcePosition position;
if (topOfAST == null) {
topOfAST = NilImplicitNode.NIL;
position = lexer.getPosition();
} else {
position = topOfAST.getPosition();
}

return new RootNode(position, result.getScope(), topOfAST);
}


ISourcePosition position = topOfAST != null ? topOfAST.getPosition() : result.getBeginNodes().get(0).getPosition();
BlockNode newTopOfAST = new BlockNode(position);
for (Node beginNode: result.getBeginNodes()) {
appendToBlock(newTopOfAST, beginNode);
@@ -44,6 +44,7 @@
import org.jruby.ast.BlockNode;
import org.jruby.ast.BlockPassNode;
import org.jruby.ast.BreakNode;
import org.jruby.ast.CallNode;
import org.jruby.ast.ClassNode;
import org.jruby.ast.ClassVarNode;
import org.jruby.ast.ClassVarAsgnNode;
@@ -1694,7 +1695,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
support.checkUselessStatement(((Node)yyVals[0+yyTop]));
}
}
support.getResult().setAST(support.addRootNode(((Node)yyVals[0+yyTop]), support.getPosition(((Node)yyVals[0+yyTop]))));
support.getResult().setAST(support.addRootNode(((Node)yyVals[0+yyTop])));
return yyVal;
}
};
@@ -309,7 +309,7 @@ program : {
support.checkUselessStatement($2);
}
}
support.getResult().setAST(support.addRootNode($2, support.getPosition($2)));
support.getResult().setAST(support.addRootNode($2));
}

top_compstmt : top_stmts opt_terms {
@@ -2099,7 +2099,7 @@ var_ref : /*mri:user_variable*/ tIDENTIFIER {
support.getConfiguration().getRuntime().getEncodingService().getLocaleEncoding()));
}
| k__LINE__ {
$$ = new FixnumNode(lexer.getPosition(), lexer.tokline.getStartLine()+1);
$$ = new FixnumNode(lexer.getPosition(), lexer.tokline.getLine()+1);
}
| k__ENCODING__ {
$$ = new EncodingNode(lexer.getPosition(), lexer.getEncoding());

0 comments on commit 3e4e479

Please sign in to comment.