KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jruby > parser > RubyParserResult


1 /***** BEGIN LICENSE BLOCK *****
2  * Version: CPL 1.0/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Common Public
5  * License Version 1.0 (the "License"); you may not use this file
6  * except in compliance with the License. You may obtain a copy of
7  * the License at http://www.eclipse.org/legal/cpl-v10.html
8  *
9  * Software distributed under the License is distributed on an "AS
10  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11  * implied. See the License for the specific language governing
12  * rights and limitations under the License.
13  *
14  * Copyright (C) 2002 Jan Arne Petersen <jpetersen@uni-bonn.de>
15  * Copyright (C) 2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
16  * Copyright (C) 2004 Thomas E Enebo <enebo@acm.org>
17  * Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
18  *
19  * Alternatively, the contents of this file may be used under the terms of
20  * either of the GNU General Public License Version 2 or later (the "GPL"),
21  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
22  * in which case the provisions of the GPL or the LGPL are applicable instead
23  * of those above. If you wish to allow use of your version of this file only
24  * under the terms of either the GPL or the LGPL, and not to allow others to
25  * use your version of this file under the terms of the CPL, indicate your
26  * decision by deleting the provisions above and replace them with the notice
27  * and other provisions required by the GPL or the LGPL. If you do not delete
28  * the provisions above, a recipient may use your version of this file under
29  * the terms of any one of the CPL, the GPL or the LGPL.
30  ***** END LICENSE BLOCK *****/

31 package org.jruby.parser;
32
33 import java.util.ArrayList JavaDoc;
34 import java.util.List JavaDoc;
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 /**
43  */

44 public class RubyParserResult {
45     private final List JavaDoc beginNodes = new ArrayList JavaDoc();
46     private final List JavaDoc endNodes = new ArrayList JavaDoc();
47     private Node ast;
48     private boolean endSeen;
49     private List JavaDoc commentNodes = new ArrayList JavaDoc();
50     private DynamicScope scope;
51
52     public List JavaDoc 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     /**
69      * Sets the ast.
70      * @param ast The ast to set
71      */

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         // FIXME: We need to add BEGIN nodes properly
82
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