1 31 package org.jruby.parser; 32 33 import java.util.ArrayList ; 34 import java.util.List ; 35 36 import org.jruby.ast.BlockNode; 37 import org.jruby.ast.CommentNode; 38 import org.jruby.ast.Node; 39 import org.jruby.lexer.yacc.ISourcePosition; 40 import org.jruby.runtime.DynamicScope; 41 42 44 public class RubyParserResult { 45 private final List beginNodes = new ArrayList (); 46 private final List endNodes = new ArrayList (); 47 private Node ast; 48 private boolean endSeen; 49 private List commentNodes = new ArrayList (); 50 private DynamicScope scope; 51 52 public List getCommentNodes() { 53 return commentNodes; 54 } 55 56 public Node getAST() { 57 return ast; 58 } 59 60 public DynamicScope getScope() { 61 return scope; 62 } 63 64 public void setScope(DynamicScope scope) { 65 this.scope = scope; 66 } 67 68 72 public void setAST(Node ast) { 73 this.ast = ast; 74 } 75 76 public void addComment(CommentNode node) { 77 commentNodes.add(node); 78 } 79 80 public void addBeginNode(StaticScope scope, Node node) { 81 beginNodes.add(node); 83 } 84 85 public void addEndNode(Node node) { 86 endNodes.add(node); 87 } 88 89 public void addAppendBeginAndEndNodes() { 90 if (beginNodes.isEmpty() && endNodes.isEmpty()) { 91 return; 92 } 93 BlockNode n; 94 if (getAST() != null) { 95 n = new BlockNode(getAST().getPosition()); 96 } else { 97 ISourcePosition p; 98 if (!beginNodes.isEmpty()) { 99 p = ((Node) beginNodes.get(0)).getPosition(); 100 } else { 101 p = ((Node) endNodes.get(endNodes.size() - 1)).getPosition(); 102 } 103 n = new BlockNode(p); 104 } 105 for (int i = 0; i < beginNodes.size(); i++) { 106 n.add((Node) beginNodes.get(i)); 107 } 108 if (getAST() != null) { 109 n.add(getAST()); 110 } 111 for (int i = endNodes.size() - 1; i >= 0; i--) { 112 n.add((Node) endNodes.get(i)); 113 } 114 setAST(n); 115 } 116 117 public boolean isEndSeen() { 118 return endSeen; 119 } 120 121 public void setEndSeen(boolean endSeen) { 122 this.endSeen = endSeen; 123 } 124 } 125 | Popular Tags |