16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | /**
32 | * Any thing which implements this represents a Callable-like node which can have a block
33 | * associated with it as part of that call. The calls which can be this are: CallNode, FCallNode,
34 | * VCallNode, and SuperNode. Blocks (the IterNode that this interface refers to can be either
35 | * an IterNode ( {...}
or do ... end
) or a BlockPassNode (&block
).
36 | *
37 | * It is likely we can remove this interface once the parser explicitly passes all iters into
38 | * the callable node during construction.
39 | */
40 | public interface BlockAcceptingNode {
41 | public Node getIter();
42 | public void setIter(Node iterNode);
43 | }
44 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/BlockArg18Node.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | import org.jrubyparser.NodeVisitor;
4 | import org.jrubyparser.SourcePosition;
5 |
6 | /**
7 | * Similiar to BlockArg, but with idiosyncracies that 1.8.7 allows:
8 | *
9 | *
10 | * proc { |a,&b| }
11 | * proc { |a,&FOO| }
12 | * proc { |a,b.c| }
13 | * proc { |a,b[0]| }
14 | *
15 | *
16 | */
17 | public class BlockArg18Node extends Node {
18 | private Node normalBlockArgs;
19 | private Node blockArgAssignee;
20 |
21 | public BlockArg18Node(SourcePosition position, Node blockArgAssignee,
22 | Node normalBlockArgs) {
23 | super(position);
24 |
25 | assert blockArgAssignee != null : "Must be a value to assign too";
26 |
27 | this.blockArgAssignee = adopt(blockArgAssignee);
28 | this.normalBlockArgs = adopt(normalBlockArgs);
29 | }
30 |
31 |
32 | /**
33 | * Checks node for 'sameness' for diffing.
34 | *
35 | * @param node to be compared to
36 | * @return Returns a boolean
37 | */
38 | @Override
39 | public boolean isSame(Node node) {
40 | if (!super.isSame(node)) return false;
41 |
42 | BlockArg18Node other = (BlockArg18Node) node;
43 |
44 | if (getArgs() == null && other.getArgs() == null) return getBlockArg().isSame(other.getBlockArg());
45 | if (getArgs() == null || other.getArgs() == null) return false;
46 |
47 | return getArgs().isSame(other.getArgs()) && getBlockArg().isSame(other.getBlockArg());
48 | }
49 |
50 |
51 |
52 | public Node getArgs() {
53 | return normalBlockArgs;
54 | }
55 |
56 | public Node getBlockArg() {
57 | return blockArgAssignee;
58 | }
59 |
60 | @Override
61 | public T accept(NodeVisitor visitor) {
62 | return visitor.visitBlockArg18Node(this);
63 | }
64 |
65 | @Override
66 | public NodeType getNodeType() {
67 | return NodeType.BLOCKARG18NODE;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/BlockNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Represents a block of nodes (read that as list).
36 | */
37 | public class BlockNode extends ListNode {
38 | public BlockNode(SourcePosition position) {
39 | super(position);
40 | }
41 |
42 | @Override
43 | public NodeType getNodeType() {
44 | return NodeType.BLOCKNODE;
45 | }
46 |
47 | /**
48 | * RubyMethod used by visitors.
49 | * accepts the visitor
50 | * @param iVisitor the visitor to accept
51 | **/
52 | @Override
53 | public T accept(NodeVisitor iVisitor) {
54 | return iVisitor.visitBlockNode(this);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/BreakNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Represents a 'break' statement.
36 | */
37 | public class BreakNode extends Node {
38 | private Node valueNode;
39 |
40 | public BreakNode(SourcePosition position, Node valueNode) {
41 | super(position);
42 |
43 | this.valueNode = adopt(valueNode);
44 | }
45 |
46 | public NodeType getNodeType() {
47 | return NodeType.BREAKNODE;
48 | }
49 |
50 | /**
51 | * Accept for the visitor pattern.
52 | * @param iVisitor the visitor
53 | **/
54 | public T accept(NodeVisitor iVisitor) {
55 | return iVisitor.visitBreakNode(this);
56 | }
57 |
58 | /**
59 | * Gets the valueNode.
60 | * @return Returns a Node
61 | */
62 | public Node getValue() {
63 | return valueNode;
64 | }
65 |
66 | @Deprecated
67 | public Node getValueNode() {
68 | return getValue();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/Colon2ConstNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 |
6 | package org.jrubyparser.ast;
7 |
8 | import org.jrubyparser.SourcePosition;
9 |
10 | /**
11 | *
12 | * @author enebo
13 | */
14 | public class Colon2ConstNode extends Colon2Node {
15 | public Colon2ConstNode(SourcePosition position, Node leftNode, String name) {
16 | super(position, leftNode, name);
17 |
18 | assert leftNode != null: "Colon2ConstNode cannot have null leftNode";
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/Colon2ImplicitNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.SourcePosition;
32 |
33 | /**
34 | * Represents a bare class declaration (e.g. class Foo/module Foo). This is slightly misnamed
35 | * since it contains no double colons (::), but our cname production needs to be a common type.
36 | * In JRuby 2, we will rename this.
37 | */
38 | public class Colon2ImplicitNode extends Colon2Node {
39 | public Colon2ImplicitNode(SourcePosition position, String name) {
40 | super(position, null, name);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/Colon2MethodNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 |
6 | package org.jrubyparser.ast;
7 |
8 | import org.jrubyparser.SourcePosition;
9 |
10 | /**
11 | * Represents a constant path which ends in a method (e.g. Foo::bar). Note: methods with
12 | * explicit parameters (e.g. Foo::bar()) will be a CallNode.
13 | */
14 | public class Colon2MethodNode extends Colon2Node {
15 | public Colon2MethodNode(SourcePosition position, Node leftNode, String name) {
16 | super(position, leftNode, name);
17 |
18 | assert leftNode != null: "class fooBar is not valid";
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/CommentNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Representation of a comment. Note that comments are not part of evaluation so you do
36 | * not get the ability to visit this node as part of evaluation. In theory we could add
37 | * this if we envisioned some wacky annotation system, but we have no crazy ideas yet.
38 | *
39 | */
40 | public class CommentNode extends SyntaxNode {
41 |
42 | public CommentNode(SourcePosition position, String content) {
43 | super(position, content);
44 | }
45 |
46 | @Override
47 | public NodeType getNodeType() {
48 | return NodeType.COMMENTNODE;
49 | }
50 |
51 | @Override
52 | public T accept(NodeVisitor visitor) {
53 | return visitor.visitCommentNode(this);
54 | }
55 |
56 | @Override
57 | public String toString() {
58 | return "Comment: " + getContent();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/ComplexNode.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | import java.util.List;
4 | import org.jrubyparser.NodeVisitor;
5 | import org.jrubyparser.SourcePosition;
6 |
7 | /**
8 | * Created by enebo on 5/21/15.
9 | */
10 | public class ComplexNode extends NumericNode implements ILiteralNode {
11 | private NumericNode y;
12 |
13 | public ComplexNode(SourcePosition position, NumericNode y) {
14 | super(position);
15 |
16 | this.y = (NumericNode) adopt(y);
17 | }
18 |
19 | @Override
20 | public T accept(NodeVisitor visitor) {
21 | return visitor.visitComplexNode(this);
22 | }
23 |
24 | @Override
25 | public List childNodes() {
26 | return createList(y);
27 | }
28 |
29 | @Override
30 | public NodeType getNodeType() {
31 | return NodeType.COMPLEXNODE;
32 | }
33 |
34 | public NumericNode getNumber() {
35 | return y;
36 | }
37 |
38 | public void setNumber(NumericNode y) {
39 | this.y = y;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/DStrNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * A string which contains some dynamic elements which needs to be evaluated (introduced by #).
36 | */
37 | public class DStrNode extends ListNode implements ILiteralNode {
38 | public DStrNode(SourcePosition position) {
39 | super(position);
40 | }
41 |
42 | @Override
43 | public NodeType getNodeType() {
44 | return NodeType.DSTRNODE;
45 | }
46 |
47 | /**
48 | * Accept for the visitor pattern.
49 | * @param iVisitor the visitor
50 | **/
51 | @Override
52 | public T accept(NodeVisitor iVisitor) {
53 | return iVisitor.visitDStrNode(this);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/DSymbolNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Node representing symbol in a form like ':"3jane"'.
36 | */
37 | public class DSymbolNode extends ListNode {
38 | /**
39 | * For mutating from a DStr to a DSym (we just create a new one with same contents).
40 | *
41 | * @param position the position
42 | * @param node to be copied
43 | */
44 | public DSymbolNode(SourcePosition position, DStrNode node) {
45 | super(position);
46 |
47 | assert node != null : "node is not null";
48 |
49 | addAll(node);
50 | }
51 |
52 | public DSymbolNode(SourcePosition position) {
53 | super(position);
54 | }
55 |
56 | @Override
57 | public NodeType getNodeType() {
58 | return NodeType.DSYMBOLNODE;
59 | }
60 |
61 | @Override
62 | public T accept(NodeVisitor visitor) {
63 | return visitor.visitDSymbolNode(this);
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/DXStrNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Dynamic backquote string. Backquote strings are eXecuted using the shell, hence the X
36 | * or maybe the X is due to the %x general quote syntax?
37 | */
38 | public class DXStrNode extends ListNode implements ILiteralNode {
39 | public DXStrNode(SourcePosition position, DStrNode node) {
40 | super(position);
41 | addAll(node);
42 | }
43 |
44 | public DXStrNode(SourcePosition position) {
45 | super(position);
46 | }
47 |
48 | @Override
49 | public NodeType getNodeType() {
50 | return NodeType.DXSTRNODE;
51 | }
52 |
53 | /**
54 | * Accept for the visitor pattern.
55 | * @param iVisitor the visitor
56 | **/
57 | @Override
58 | public T accept(NodeVisitor iVisitor) {
59 | return iVisitor.visitDXStrNode(this);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/DefnNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import java.util.List;
32 |
33 | import org.jrubyparser.NodeVisitor;
34 | import org.jrubyparser.SourcePosition;
35 | import org.jrubyparser.StaticScope;
36 | import org.jrubyparser.util.ILocalVariableVisitor;
37 |
38 | /**
39 | * method definition node.
40 | */
41 | public class DefnNode extends MethodDefNode {
42 | public DefnNode(SourcePosition position, MethodNameNode nameNode, ArgsNode argsNode,
43 | StaticScope scope, Node bodyNode) {
44 | super(position, nameNode, argsNode, scope, bodyNode);
45 | }
46 |
47 | public NodeType getNodeType() {
48 | return NodeType.DEFNNODE;
49 | }
50 |
51 | public T accept(NodeVisitor iVisitor) {
52 | return iVisitor.visitDefnNode(this);
53 | }
54 |
55 | public List getVariableReferencesNamed(String name) {
56 | return ILocalVariableVisitor.findOccurrencesIn(this, name);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/EncodingNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Represents __ENCODING__.
36 | */
37 | public class EncodingNode extends Node {
38 | public EncodingNode(SourcePosition position) {
39 | super(position);
40 | }
41 |
42 | @Override
43 | public T accept(NodeVisitor visitor) {
44 | return visitor.visitEncodingNode(this);
45 | }
46 |
47 | @Override
48 | public NodeType getNodeType() {
49 | return NodeType.ENCODINGNODE;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/FalseNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Represents a false literal.
36 | */
37 | public class FalseNode extends BareKeywordNode {
38 | public FalseNode(SourcePosition position) {
39 | super(position, "false");
40 | }
41 |
42 | public NodeType getNodeType() {
43 | return NodeType.FALSENODE;
44 | }
45 |
46 | /**
47 | * Accept for the visitor pattern.
48 | * @param iVisitor the visitor
49 | **/
50 | public T accept(NodeVisitor iVisitor) {
51 | return iVisitor.visitFalseNode(this);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/FileNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.SourcePosition;
32 |
33 | /**
34 | * Represents __FILE__ nodes
35 | */
36 | public class FileNode extends StrNode {
37 | public FileNode(SourcePosition position, String value) {
38 | super(position, value);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/IArgumentNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | /**
32 | * Does the node contain an argument list?
33 | */
34 | public interface IArgumentNode {
35 | public Node getArgs();
36 | public void setArgs(Node argsNode);
37 | public boolean hasParens();
38 | public void setHasParens(boolean hasParens);
39 | }
40 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/IBlockScope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package org.jrubyparser.ast;
6 |
7 | /**
8 | * A Scope which is a variable scope for a block.
9 | */
10 | public interface IBlockScope extends IScope, IParameterScope {
11 | }
12 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/IClassVariable.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | /**
4 | * Marker for Class variable nodes (ClassVarNode, ClassVarAsgnNode, ClassVarDeclNode).
5 | */
6 | public interface IClassVariable extends INameNode {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/IGlobalVariable.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | /**
4 | * Besides basic global variables (gvar, gasgn) there are special gvars (backref, nthref).
5 | */
6 | public interface IGlobalVariable extends INameNode {
7 | }
8 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/IInstanceVariable.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | /**
4 | * Marker interface for instance variable (instasgn, instvar).
5 | */
6 | public interface IInstanceVariable extends INameNode {
7 | }
8 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/ILiteralNode.java:
--------------------------------------------------------------------------------
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) 2009 Thomas E. Enebo
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 | package org.jrubyparser.ast;
29 |
30 | /**
31 | * A marker for literal nodes.
32 | */
33 | public interface ILiteralNode {
34 | // only a marker interface
35 | }
36 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/ILocalScope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package org.jrubyparser.ast;
6 |
7 | /**
8 | * Marker Interface to identify local variable scope versus block local variable scopes.
9 | */
10 | public interface ILocalScope extends IScope {
11 | }
12 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/ILocalVariable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package org.jrubyparser.ast;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Simple marker interface to indicate this node type is a type of local variable (block or local).
11 | */
12 | public interface ILocalVariable extends INameNode {
13 | /**
14 | * Which Variable Scope does this variable belong to? Note that RootNode is a special ILocalScope
15 | * for the implicit scope created at top-level.
16 | *
17 | * @return the defined scope
18 | */
19 | public IScope getDefinedScope();
20 |
21 | /**
22 | * Retrieve the node which is responsible for declaring this one. This can be a variable
23 | * or a parameter.
24 | *
25 | * @return the declaration variable
26 | */
27 | public ILocalVariable getDeclaration();
28 |
29 | /**
30 | * Find all occurrences of this variable including itself.
31 | *
32 | * @return the list of all occurrences.
33 | */
34 | public List getOccurrences();
35 | }
36 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/IModuleScope.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Marker interface to indicate a Module/Class/SClass (all extend module in Ruby semantics).
7 | */
8 | public interface IModuleScope {
9 | /**
10 | * Methods defined on the module.
11 | *
12 | * @return A List containing all the MethodDefNode's defined on a module.
13 | */
14 | public List getMethodDefs();
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/INameMatchable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package org.jrubyparser.ast;
6 |
7 | /**
8 | * A node of this type can determine whether it matches a supplied String name
9 | */
10 | public interface INameMatchable {
11 | public boolean isNameMatch(String name);
12 | }
13 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/INameNode.java:
--------------------------------------------------------------------------------
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) 2009 Thomas E. Enebo
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 | package org.jrubyparser.ast;
29 |
30 | import org.jrubyparser.SourcePosition;
31 |
32 | public interface INameNode extends INameMatchable {
33 | /**
34 | * Get the plain name without sigils.
35 | *
36 | * @return the name
37 | */
38 | public String getName();
39 |
40 | /**
41 | * Get the name including any leading sigils.
42 | *
43 | * @return the lexical name
44 | */
45 | public String getLexicalName();
46 |
47 | /**
48 | * Set the name (name should not include sigils).
49 | *
50 | * @param newName the new name
51 | */
52 | public void setName(String newName);
53 |
54 | /**
55 | * The position of just the name part of the node.
56 | *
57 | * @return the names positions
58 | */
59 | public SourcePosition getNamePosition();
60 |
61 | /**
62 | * The position of the name + any sigils that come with it.
63 | *
64 | * @return the lexical names positions
65 | */
66 | public SourcePosition getLexicalNamePosition();
67 | }
68 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/IParameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package org.jrubyparser.ast;
6 |
7 | /**
8 | * For 1.9+ we can tell if a node is a parameter or not. This interface makes that
9 | * determination simpler.
10 | */
11 | public interface IParameter extends ILocalVariable {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/IParameterScope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package org.jrubyparser.ast;
6 |
7 | /**
8 | *
9 | */
10 | public interface IParameterScope {
11 | public boolean isParameterUsed(String name);
12 | public ILocalVariable getParameterNamed(String name);
13 | }
14 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/IScope.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Represents a variable scope (block or local).
7 | */
8 | public interface IScope {
9 | public List getVariableReferencesNamed(String name);
10 | }
11 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/IScopingNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | public interface IScopingNode {
32 | public Colon3Node getCPath();
33 | }
34 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/ImplicitNilNode.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | import org.jrubyparser.NodeVisitor;
4 | import org.jrubyparser.SourcePosition;
5 |
6 | /**
7 | * This node represent those strange places where we have what it a valid semantic element
8 | * but syntactically it is not there: [1, (), 3]. The parens here are syntax and evaluating
9 | * it will return nil but a nil is not actually there.
10 | */
11 | public class ImplicitNilNode extends Node {
12 | public ImplicitNilNode(SourcePosition position) {
13 | super(position);
14 | }
15 |
16 | @Override
17 | public T accept(NodeVisitor visitor) {
18 | return visitor.visitImplicitNilNode(this);
19 | }
20 |
21 | @Override
22 | public NodeType getNodeType() {
23 | return NodeType.IMPLICITNILNODE;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/KeywordArgNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package org.jrubyparser.ast;
6 |
7 | import org.jrubyparser.NodeVisitor;
8 | import org.jrubyparser.SourcePosition;
9 |
10 | /**
11 | *
12 | * @author enebo
13 | */
14 | public class KeywordArgNode extends Node {
15 | private AssignableNode assignable;
16 |
17 | public KeywordArgNode(SourcePosition position, AssignableNode assignable) {
18 | super(position);
19 | this.assignable = assignable;
20 | }
21 |
22 |
23 | /**
24 | * Checks node for 'sameness' for diffing.
25 | *
26 | * @param node to be compared to
27 | * @return Returns a boolean
28 | */
29 | @Override
30 | public boolean isSame(Node node) {
31 | return super.isSame(node) && getAssignable().isSame(((KeywordArgNode) node).getAssignable());
32 | }
33 |
34 |
35 | @Override
36 | public T accept(NodeVisitor visitor) {
37 | return visitor.visitKeywordArgNode(this);
38 | }
39 |
40 | @Override
41 | public NodeType getNodeType() {
42 | return NodeType.KEYWORDARGNODE;
43 | }
44 |
45 | public AssignableNode getAssignable() {
46 | return assignable;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/KeywordRestArgNode.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | import org.jrubyparser.NodeVisitor;
4 | import org.jrubyparser.SourcePosition;
5 |
6 | /**
7 | *
8 | */
9 | public class KeywordRestArgNode extends ArgumentNode {
10 | public KeywordRestArgNode(SourcePosition position, String name, int index) {
11 | super(position, name, index);
12 | }
13 |
14 | @Override
15 | public T accept(NodeVisitor visitor) {
16 | return visitor.visitKeywordRestArgNode(this);
17 | }
18 |
19 | @Override
20 | public NodeType getNodeType() {
21 | return NodeType.KEYWORDRESTARGNODE;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/LambdaNode.java:
--------------------------------------------------------------------------------
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) 2009 Thomas E. Enebo
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 | package org.jrubyparser.ast;
29 |
30 | import org.jrubyparser.NodeVisitor;
31 | import org.jrubyparser.SourcePosition;
32 | import org.jrubyparser.StaticScope;
33 |
34 | /**
35 | * Stubby lambda node (1.9 only)
36 | */
37 | public class LambdaNode extends IterNode {
38 | public LambdaNode(SourcePosition position, ArgsNode args, Node body, StaticScope scope) {
39 | super(position, args, body, scope);
40 | }
41 |
42 | @Override
43 | public NodeType getNodeType() {
44 | return NodeType.LAMBDANODE;
45 | }
46 |
47 | public ArgsNode getArgs() {
48 | return (ArgsNode)getVar();
49 | }
50 |
51 | @Override
52 | public T accept(NodeVisitor visitor) {
53 | return visitor.visitLambdaNode(this);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/LiteralNode.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | import org.jrubyparser.NodeVisitor;
4 | import org.jrubyparser.lexer.Token;
5 |
6 | /**
7 | * This is not a node in the classic sense in that it has no defined or
8 | * interpret method which can be called. It just stores the position of
9 | * the literal and the name/value of the literal. We made it a node so that
10 | * the parser needs to work less hard in its productions. dynamic literals
11 | * are nodes and by having literals also be nodes means they have a common
12 | * subtype which is not Object.
13 | */
14 | public class LiteralNode extends Node {
15 | private String name;
16 |
17 | public LiteralNode(Token token) {
18 | super(token.getPosition());
19 |
20 | this.name = (String) token.getValue();
21 | }
22 |
23 |
24 | /**
25 | * Checks node for 'sameness' for diffing.
26 | *
27 | * @param node to be compared to
28 | * @return Returns a boolean
29 | */
30 | @Override
31 | public boolean isSame(Node node) {
32 | return super.isSame(node) && getName().equals(((LiteralNode) node).getName());
33 | }
34 |
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | /**
41 | * Accept for the visitor pattern.
42 | * @param iVisitor the visitor
43 | **/
44 | public T accept(NodeVisitor iVisitor) {
45 | return iVisitor.visitLiteralNode(this);
46 | }
47 |
48 | @Override
49 | public NodeType getNodeType() {
50 | return NodeType.LITERALNODE;
51 | }
52 |
53 | }
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/MethodNameNode.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | import org.jrubyparser.NodeVisitor;
4 | import org.jrubyparser.SourcePosition;
5 |
6 | /**
7 | * Node to hold string value of a methods name (for either Defn or Defs).
8 | */
9 | public class MethodNameNode extends NamedNode {
10 | public MethodNameNode(SourcePosition position, String name) {
11 | super(position, name);
12 | }
13 |
14 | public NodeType getNodeType() {
15 | return NodeType.METHODNAMENODE;
16 | }
17 |
18 | public T accept(NodeVisitor visitor) {
19 | return visitor.visitMethodNameNode(this);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/NamedNode.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | import org.jrubyparser.SourcePosition;
4 |
5 | /**
6 | * Nodes with string names are very common.
7 | */
8 | public abstract class NamedNode extends Node implements INameNode {
9 | private String name;
10 |
11 | public NamedNode(SourcePosition position, String name) {
12 | super(position);
13 |
14 | assert name != null : "Name node with no null name";
15 |
16 | this.name = name;
17 | }
18 |
19 |
20 | /**
21 | * Checks node for 'sameness' for diffing.
22 | *
23 | * @param node to be compared to
24 | * @return Returns a boolean
25 | */
26 | @Override
27 | public boolean isSame(Node node) {
28 | return super.isSame(node) && isNameMatch(((NamedNode) node).getName());
29 | }
30 |
31 |
32 | public String getLexicalName() {
33 | return getName();
34 | }
35 |
36 | /**
37 | * Gets the name.
38 | * @return Returns a String
39 | */
40 | public String getName() {
41 | return name;
42 | }
43 |
44 | /**
45 | * Sets the name (for refactoring support)
46 | * @param name is the new name
47 | */
48 | public void setName(String name) {
49 | this.name = name;
50 | }
51 |
52 | /**
53 | * Does the supplied name match this one?
54 | * @param testName name to match
55 | * @return true if the same name
56 | */
57 | public boolean isNameMatch(String testName) {
58 | return name.equals(testName);
59 | }
60 |
61 | public SourcePosition getNamePosition() {
62 | return getPosition();
63 | }
64 |
65 | public SourcePosition getLexicalNamePosition() {
66 | return getPosition();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/NextNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Represents a 'next' statement.
36 | */
37 | public class NextNode extends Node {
38 | private Node valueNode;
39 |
40 | public NextNode(SourcePosition position, Node valueNode) {
41 | super(position);
42 |
43 | this.valueNode = adopt(valueNode);
44 | }
45 |
46 | public NodeType getNodeType() {
47 | return NodeType.NEXTNODE;
48 | }
49 |
50 | /**
51 | * Accept for the visitor pattern.
52 | * @param iVisitor the visitor
53 | **/
54 | public T accept(NodeVisitor iVisitor) {
55 | return iVisitor.visitNextNode(this);
56 | }
57 |
58 | /**
59 | * Gets the valueNode.
60 | * @return Returns a Node
61 | */
62 | public Node getValue() {
63 | return valueNode;
64 | }
65 |
66 | @Deprecated
67 | public Node getValueNode() {
68 | return getValue();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/NilNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * represents 'nil'
36 | */
37 | public class NilNode extends BareKeywordNode {
38 | public NilNode(SourcePosition position) {
39 | super(position, "nil");
40 | }
41 |
42 | public NodeType getNodeType() {
43 | return NodeType.NILNODE;
44 | }
45 |
46 | /**
47 | * Accept for the visitor pattern.
48 | * @param iVisitor the visitor
49 | **/
50 | public T accept(NodeVisitor iVisitor) {
51 | return iVisitor.visitNilNode(this);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/NumericNode.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 |
4 | import org.jrubyparser.SourcePosition;
5 |
6 | /**
7 | * Any node representing a numeric value.
8 | */
9 | public abstract class NumericNode extends Node implements ILiteralNode {
10 | public NumericNode(SourcePosition position) {
11 | super(position);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/OpAsgnAndNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | public class OpAsgnAndNode extends BinaryOperatorBaseNode {
35 | public OpAsgnAndNode(SourcePosition position, Node headNode, Node valueNode) {
36 | super(position, headNode, valueNode);
37 | }
38 |
39 | @Override
40 | public NodeType getNodeType() {
41 | return NodeType.OPASGNANDNODE;
42 | }
43 |
44 | /**
45 | * Accept for the visitor pattern.
46 | * @param iVisitor the visitor
47 | **/
48 | public T accept(NodeVisitor iVisitor) {
49 | return iVisitor.visitOpAsgnAndNode(this);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/OpAsgnOrNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | public class OpAsgnOrNode extends BinaryOperatorBaseNode {
35 | public OpAsgnOrNode(SourcePosition position, Node headNode, Node valueNode) {
36 | super(position, headNode, valueNode);
37 | }
38 |
39 | @Override
40 | public NodeType getNodeType() {
41 | return NodeType.OPASGNORNODE;
42 | }
43 |
44 | /**
45 | * Accept for the visitor pattern.
46 | * @param iVisitor the visitor
47 | **/
48 | public T accept(NodeVisitor iVisitor) {
49 | return iVisitor.visitOpAsgnOrNode(this);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/OpElementAsgnAndNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2013 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.SourcePosition;
32 |
33 | /**
34 | *
35 | */
36 | public class OpElementAsgnAndNode extends OpElementAsgnNode {
37 | public OpElementAsgnAndNode(SourcePosition position, Node receiverNode, String operatorName, Node argsNode, Node valueNode) {
38 | super(position, receiverNode, operatorName, argsNode, valueNode);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/OpElementAsgnOrNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2013 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.SourcePosition;
32 |
33 | /**
34 | *
35 | */
36 | public class OpElementAsgnOrNode extends OpElementAsgnNode {
37 | public OpElementAsgnOrNode(SourcePosition position, Node receiverNode, String operatorName, Node argsNode, Node valueNode) {
38 | super(position, receiverNode, operatorName, argsNode, valueNode);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/OrNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * represents '||' (or) statements
36 | */
37 | public class OrNode extends BinaryOperatorBaseNode {
38 | public OrNode(SourcePosition position, Node firstNode, Node secondNode) {
39 | super(position, firstNode, secondNode);
40 | }
41 |
42 | @Override
43 | public NodeType getNodeType() {
44 | return NodeType.ORNODE;
45 | }
46 |
47 | /**
48 | * Accept for the visitor pattern.
49 | * @param iVisitor the visitor
50 | **/
51 | public T accept(NodeVisitor iVisitor) {
52 | return iVisitor.visitOrNode(this);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/PostExeNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Captures END statements (END {...})
36 | */
37 | public class PostExeNode extends IterNode {
38 | public PostExeNode(SourcePosition position, Node body) {
39 | super(position, null, null, body);
40 | }
41 |
42 | @Override
43 | public NodeType getNodeType() {
44 | return NodeType.POSTEXENODE;
45 | }
46 |
47 | /**
48 | * Accept for the visitor pattern.
49 | * @param iVisitor the visitor
50 | **/
51 | @Override
52 | public T accept(NodeVisitor iVisitor) {
53 | return iVisitor.visitPostExeNode(this);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/PreExe19Node.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2007 Thomas E Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 | import org.jrubyparser.StaticScope;
34 |
35 | /**
36 | * A pre-execution construction (BEGIN { ... }).
37 | */
38 | public class PreExe19Node extends PreExeNode {
39 | public PreExe19Node(SourcePosition position, StaticScope scope, Node body) {
40 | super(position, scope, body);
41 | }
42 |
43 | @Override
44 | public NodeType getNodeType() {
45 | return NodeType.PREEXENODE;
46 | }
47 |
48 | @Override
49 | public T accept(NodeVisitor iVisitor) {
50 | return iVisitor.visitPreExeNode(this);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/PreExeNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 | import org.jrubyparser.StaticScope;
34 |
35 | /**
36 | * A pre-execution construction (BEGIN { ... }).
37 | */
38 | public class PreExeNode extends IterNode {
39 | public PreExeNode(SourcePosition position, StaticScope scope, Node body) {
40 | super(position, null, scope, body);
41 | }
42 |
43 | @Override
44 | public NodeType getNodeType() {
45 | return NodeType.PREEXENODE;
46 | }
47 |
48 | @Override
49 | public T accept(NodeVisitor iVisitor) {
50 | return iVisitor.visitPreExeNode(this);
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/RationalNode.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | import java.util.List;
4 | import org.jrubyparser.NodeVisitor;
5 | import org.jrubyparser.SourcePosition;
6 |
7 | /**
8 | * Created by enebo on 5/21/15.
9 | */
10 | public class RationalNode extends NumericNode {
11 | private final long numerator;
12 | private final long denominator;
13 |
14 | public RationalNode(SourcePosition position, long numerator, long denominator) {
15 | super(position);
16 |
17 | this.numerator = numerator;
18 | this.denominator = denominator;
19 | }
20 |
21 | @Override
22 | public T accept(NodeVisitor visitor) {
23 | return visitor.visitRationalNode(this);
24 | }
25 |
26 | @Override
27 | public NodeType getNodeType() {
28 | return NodeType.RATIONALNODE;
29 | }
30 |
31 | public long getNumerator() {
32 | return numerator;
33 | }
34 |
35 | public long getDenominator() {
36 | return denominator;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/RedoNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Represents a 'redo'
36 | */
37 | public class RedoNode extends Node {
38 | public RedoNode(SourcePosition position) {
39 | super(position);
40 | }
41 |
42 | public NodeType getNodeType() {
43 | return NodeType.REDONODE;
44 | }
45 |
46 | /**
47 | * Accept for the visitor pattern.
48 | * @param iVisitor the visitor
49 | **/
50 | public T accept(NodeVisitor iVisitor) {
51 | return iVisitor.visitRedoNode(this);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/RequiredKeywordArgumentValueNode.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | import java.util.Collections;
4 | import java.util.List;
5 | import org.jrubyparser.NodeVisitor;
6 | import org.jrubyparser.SourcePosition;
7 |
8 | /**
9 | * Marker to indicate that rather than assigning nil (where in multiple
10 | * places we have nulls getting implicitly converted to nils) we should
11 | * raise an error.
12 | *
13 | * MRI passes a -1 as a special value so we are doing something similar
14 | * but more explicit.
15 | */
16 | public class RequiredKeywordArgumentValueNode extends Node {
17 | public RequiredKeywordArgumentValueNode(SourcePosition position) {
18 | super(position);
19 | }
20 |
21 | @Override
22 | public T accept(NodeVisitor visitor) {
23 | return visitor.visitRequiredKeywordArgumentValueNode(this);
24 | }
25 |
26 | @Override
27 | public List childNodes() {
28 | return Collections.emptyList();
29 | }
30 |
31 | @Override
32 | public NodeType getNodeType() {
33 | return NodeType.REQUIREDKEYWORDARGNODE;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/RetryNode.java:
--------------------------------------------------------------------------------
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) 2009 Thomas E. Enebo
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 | package org.jrubyparser.ast;
29 |
30 | import org.jrubyparser.NodeVisitor;
31 | import org.jrubyparser.SourcePosition;
32 |
33 | /**
34 | * Represents a 'retry' statement.
35 | */
36 | public class RetryNode extends Node {
37 | public RetryNode(SourcePosition position) {
38 | super(position);
39 | }
40 |
41 | public NodeType getNodeType() {
42 | return NodeType.RETRYNODE;
43 | }
44 |
45 | /**
46 | * Accept for the visitor pattern.
47 | * @param iVisitor the visitor
48 | **/
49 | public T accept(NodeVisitor iVisitor) {
50 | return iVisitor.visitRetryNode(this);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/SValueNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | public class SValueNode extends Node {
35 | private Node node;
36 |
37 | public SValueNode(SourcePosition position, Node node) {
38 | super(position);
39 |
40 | assert node != null : "node is not null";
41 |
42 | this.node = adopt(node);
43 | }
44 |
45 | @Override
46 | public boolean isSame(Node other) {
47 | return super.isSame(other) && getValue().isSame(((SValueNode) other).getValue());
48 | }
49 |
50 | public NodeType getNodeType() {
51 | return NodeType.SVALUENODE;
52 | }
53 |
54 | public T accept(NodeVisitor visitor) {
55 | return visitor.visitSValueNode(this);
56 | }
57 |
58 | public Node getValue() {
59 | return node;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/SelfNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Represents 'self' keyword
36 | */
37 | public class SelfNode extends BareKeywordNode {
38 | public SelfNode(SourcePosition position) {
39 | super(position, "self");
40 | }
41 |
42 | public NodeType getNodeType() {
43 | return NodeType.SELFNODE;
44 | }
45 |
46 | /**
47 | * Accept for the visitor pattern.
48 | * @param iVisitor the visitor
49 | **/
50 | public T accept(NodeVisitor iVisitor) {
51 | return iVisitor.visitSelfNode(this);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/SplatNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | public class SplatNode extends Node {
35 | private Node node;
36 |
37 | public SplatNode(SourcePosition position, Node node) {
38 | super(position);
39 |
40 | assert node != null : "node is not null";
41 |
42 | this.node = adopt(node);
43 | }
44 |
45 | @Override
46 | public boolean isSame(Node other) {
47 | return super.isSame(other) && getValue().isSame(((SplatNode) other).getValue());
48 | }
49 |
50 | public NodeType getNodeType() {
51 | return NodeType.SPLATNODE;
52 | }
53 |
54 | public T accept(NodeVisitor visitor) {
55 | return visitor.visitSplatNode(this);
56 | }
57 |
58 | public Node getValue() {
59 | return node;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/StarNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Represents the unassignable star in a multiple assignent (e.g. a,b,* = arr).
36 | *
37 | * AssignmentVisitor.multiAssign checks for this (this is never visited directly)
38 | */
39 | public class StarNode extends Node {
40 | /**
41 | * Constructor for StarNode.
42 | * @param position the position
43 | */
44 | public StarNode(SourcePosition position) {
45 | super(position);
46 | }
47 |
48 | public NodeType getNodeType() {
49 | return NodeType.STARNODE;
50 | }
51 |
52 | /**
53 | * @see Node#accept(NodeVisitor)
54 | */
55 | public T accept(NodeVisitor visitor) {
56 | return null; // never visited, should be fine
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/SymbolNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | //FIXME: I don't think this should be a namednode/inamenode but I need to audit how it is used.
35 | /**
36 | * Represents a symbol (:symbol_name).
37 | */
38 | public class SymbolNode extends NamedNode implements ILiteralNode, INameNode {
39 | public SymbolNode(SourcePosition position, String name) {
40 | super(position, name);
41 | }
42 |
43 | public NodeType getNodeType() {
44 | return NodeType.SYMBOLNODE;
45 | }
46 |
47 | public T accept(NodeVisitor iVisitor) {
48 | return iVisitor.visitSymbolNode(this);
49 | }
50 |
51 | @Override
52 | public String getLexicalName() {
53 | return ":" + getName();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/ToAryNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | // 1.8-only node
35 | public class ToAryNode extends Node {
36 | private Node node;
37 |
38 | public ToAryNode(SourcePosition position, Node node) {
39 | super(position);
40 |
41 | this.node = adopt(node);
42 | }
43 |
44 | public NodeType getNodeType() {
45 | return NodeType.TOARYNODE;
46 | }
47 |
48 | public T accept(NodeVisitor visitor) {
49 | return visitor.visitToAryNode(this);
50 | }
51 |
52 | public Node getValue() {
53 | return node;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/TrueNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Represents 'true'.
36 | */
37 | public class TrueNode extends BareKeywordNode {
38 | public TrueNode(SourcePosition position) {
39 | super(position, "true");
40 | }
41 |
42 | public NodeType getNodeType() {
43 | return NodeType.TRUENODE;
44 | }
45 |
46 | /**
47 | * Accept for the visitor pattern.
48 | * @param iVisitor the visitor
49 | **/
50 | public T accept(NodeVisitor iVisitor) {
51 | return iVisitor.visitTrueNode(this);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/TypedArgumentNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 |
6 | package org.jrubyparser.ast;
7 |
8 | import org.jrubyparser.SourcePosition;
9 |
10 | /**
11 | *
12 | * @author enebo
13 | */
14 | public class TypedArgumentNode extends ArgumentNode {
15 | private Node typeNode;
16 |
17 | public TypedArgumentNode(SourcePosition position, String identifier, Node typeNode) {
18 | super(position, identifier);
19 |
20 | this.typeNode = adopt(typeNode);
21 | }
22 |
23 | public Node getTypeNode() {
24 | return typeNode;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/UndefNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * Represents an 'undef' statement.
36 | */
37 | public class UndefNode extends Node {
38 | private Node name;
39 |
40 | public UndefNode(SourcePosition position, Node name) {
41 | super(position);
42 | this.name = adopt(name);
43 | }
44 |
45 | @Override
46 | public boolean isSame(Node other) {
47 | return super.isSame(other) && getName().isSame(((UndefNode) other).getName());
48 | }
49 |
50 | public NodeType getNodeType() {
51 | return NodeType.UNDEFNODE;
52 | }
53 |
54 | /**
55 | * Accept for the visitor pattern.
56 | * @param iVisitor the visitor
57 | **/
58 | public T accept(NodeVisitor iVisitor) {
59 | return iVisitor.visitUndefNode(this);
60 | }
61 |
62 | /**
63 | * Gets the name.
64 | * @return Returns a String
65 | */
66 | public Node getName() {
67 | return name;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/UnnamedRestArgNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.SourcePosition;
32 |
33 | /**
34 | * a bare '*'
35 | */
36 | public class UnnamedRestArgNode extends RestArgNode {
37 | public UnnamedRestArgNode(SourcePosition position, String name, int index) {
38 | super(position, name, index);
39 | }
40 |
41 | public UnnamedRestArgNode(SourcePosition position, int index) {
42 | this(position, "", index);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/VCallNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | * RubyMethod call without any arguments
36 | */
37 | public class VCallNode extends NamedNode implements INameNode {
38 | public VCallNode(SourcePosition position, String name) {
39 | super(position, name);
40 | }
41 |
42 | public NodeType getNodeType() {
43 | return NodeType.VCALLNODE;
44 | }
45 |
46 | /**
47 | * Accept for the visitor pattern.
48 | * @param iVisitor the visitor
49 | **/
50 | public T accept(NodeVisitor iVisitor) {
51 | return iVisitor.visitVCallNode(this);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/ZArrayNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /**
35 | *
36 | * zero length list
37 | *
38 | */
39 | public class ZArrayNode extends Node implements ILiteralNode {
40 | public ZArrayNode(SourcePosition position) {
41 | super(position);
42 | }
43 |
44 | public NodeType getNodeType() {
45 | return NodeType.ZARRAYNODE;
46 | }
47 |
48 | /**
49 | * Accept for the visitor pattern.
50 | * @param iVisitor the visitor
51 | **/
52 | public T accept(NodeVisitor iVisitor) {
53 | return iVisitor.visitZArrayNode(this);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/ZYieldNode.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.ast;
2 |
3 | import org.jrubyparser.SourcePosition;
4 |
5 | /**
6 | * A Yield node with no parens
7 | */
8 | public class ZYieldNode extends YieldNode {
9 | public ZYieldNode(SourcePosition position) {
10 | super(position, null, true);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/ast/ZeroArgNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E. Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.ast;
30 |
31 | import org.jrubyparser.NodeVisitor;
32 | import org.jrubyparser.SourcePosition;
33 |
34 | /** Represents a zero arg in a block.
35 | * this is never visited and is used only in an instanceof check
36 | *
37 | * do ||
38 | * end
39 | *
40 | *
41 | */
42 | public class ZeroArgNode extends Node {
43 | public ZeroArgNode(SourcePosition position) {
44 | super(position);
45 | }
46 |
47 | public NodeType getNodeType() {
48 | return NodeType.ZEROARGNODE;
49 | }
50 |
51 | /**
52 | * @see Node#accept(NodeVisitor)
53 | */
54 | public T accept(NodeVisitor visitor) {
55 | return null; // never visited, should be ok
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/lexer/StackState.java:
--------------------------------------------------------------------------------
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
15 | * Copyright (C) 2004 Stefan Matthias Aust
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.lexer;
30 |
31 | /**
32 | *
33 | * @author jpetersen
34 | */
35 | public class StackState implements Cloneable {
36 | private long stack = 0;
37 |
38 | public void reset() {
39 | reset(0);
40 | }
41 |
42 | public void reset(long backup) {
43 | stack = backup;
44 | }
45 |
46 | // PUSH(1)
47 | public long begin() {
48 | long old = stack;
49 | stack <<= 1;
50 | stack |= 1;
51 | return old;
52 | }
53 |
54 | // POP
55 | public void end() {
56 | stack >>= 1;
57 | }
58 |
59 | // PUSH(0). If you look at original macro: stack |= (n&1) => stack |= 0 => no-change.
60 | public void stop() {
61 | stack <<= 1;
62 | }
63 |
64 | // LEXPOP
65 | public void restart() {
66 | stack |= (stack & 1) << 1;
67 | stack >>= 1;
68 | }
69 |
70 | // SET_P
71 | public boolean isInState() {
72 | return (stack & 1) != 0;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/parser/ArgsTailHolder.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.parser;
2 |
3 | import org.jrubyparser.ISourcePositionHolder;
4 | import org.jrubyparser.SourcePosition;
5 | import org.jrubyparser.ast.BlockArgNode;
6 | import org.jrubyparser.ast.KeywordRestArgNode;
7 | import org.jrubyparser.ast.ListNode;
8 |
9 | /**
10 | * Simple struct to hold values until they can be inserted into the AST.
11 | */
12 | public class ArgsTailHolder implements ISourcePositionHolder {
13 | private SourcePosition position;
14 | private BlockArgNode blockArg;
15 | private ListNode keywordArgs;
16 | private KeywordRestArgNode keywordRestArg;
17 |
18 | public ArgsTailHolder(SourcePosition position, ListNode keywordArgs,
19 | KeywordRestArgNode keywordRestArg, BlockArgNode blockArg) {
20 | this.position = position;
21 | this.blockArg = blockArg;
22 | this.keywordArgs = keywordArgs;
23 | this.keywordRestArg = keywordRestArg;
24 | }
25 |
26 | public SourcePosition getPosition() {
27 | return position;
28 | }
29 |
30 | public void setPosition(SourcePosition position) {
31 | this.position = position;
32 | }
33 |
34 | public BlockArgNode getBlockArg() {
35 | return blockArg;
36 | }
37 |
38 | public ListNode getKeywordArgs() {
39 | return keywordArgs;
40 | }
41 |
42 | public KeywordRestArgNode getKeywordRestArgNode() {
43 | return keywordRestArg;
44 | }
45 |
46 | /**
47 | * Does this holder support either keyword argument types
48 | * @return true if there are keyword args
49 | */
50 | public boolean hasKeywordArgs() {
51 | return keywordArgs != null || keywordRestArg != null;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/parser/ParserState.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.parser;
2 |
3 | import org.jrubyparser.lexer.Lexer;
4 |
5 | public interface ParserState {
6 | public Object execute(ParserSupport support, Lexer lexer, Object yyVal, Object[] yyVals, int yyTop);
7 | }
8 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/parser/ReOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2009 Thomas E Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.parser;
30 |
31 | public interface ReOptions {
32 | int RE_OPTION_IGNORECASE = 1;
33 | int RE_OPTION_EXTENDED = 2;
34 | int RE_OPTION_MULTILINE = 4;
35 | int RE_OPTION_SINGLELINE = 8;
36 | int RE_OPTION_POSIXLINE = (RE_OPTION_MULTILINE | RE_OPTION_SINGLELINE);
37 | int RE_OPTION_LONGEST = 16;
38 | int RE_MAY_IGNORECASE = 32;
39 | int RE_UNICODE = 64;
40 | int RE_OPTION_ONCE = 0x80; // odd...but it is odd in ruby too.
41 | }
42 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/parser/RubyParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | ***** BEGIN LICENSE BLOCK *****
3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1
4 | *
5 | * The contents of this file are subject to the Common Public
6 | * License Version 1.0 (the "License"); you may not use this file
7 | * except in compliance with the License. You may obtain a copy of
8 | * the License at http://www.eclipse.org/legal/cpl-v10.html
9 | *
10 | * Software distributed under the License is distributed on an "AS
11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 | * implied. See the License for the specific language governing
13 | * rights and limitations under the License.
14 | *
15 | * Copyright (C) 2008 Thomas E Enebo
16 | *
17 | * Alternatively, the contents of this file may be used under the terms of
18 | * either of the GNU General Public License Version 2 or later (the "GPL"),
19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20 | * in which case the provisions of the GPL or the LGPL are applicable instead
21 | * of those above. If you wish to allow use of your version of this file only
22 | * under the terms of either the GPL or the LGPL, and not to allow others to
23 | * use your version of this file under the terms of the CPL, indicate your
24 | * decision by deleting the provisions above and replace them with the notice
25 | * and other provisions required by the GPL or the LGPL. If you do not delete
26 | * the provisions above, a recipient may use your version of this file under
27 | * the terms of any one of the CPL, the GPL or the LGPL.
28 | ***** END LICENSE BLOCK *****/
29 | package org.jrubyparser.parser;
30 |
31 | import java.io.IOException;
32 | import org.jrubyparser.IRubyWarnings;
33 | import org.jrubyparser.lexer.LexerSource;
34 |
35 | /**
36 | * Common interface specifying the contract of Ruby parsers (1.8.6 + 1.9)
37 | */
38 | public interface RubyParser {
39 | public ParserResult parse(ParserConfiguration configuration, LexerSource source) throws IOException;
40 | public void setWarnings(IRubyWarnings warnings);
41 | }
42 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/parser/YyTables.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.parser;
2 |
3 | public class YyTables {
4 | private static short[] combine(short[] t1, short[] t2,
5 | short[] t3, short[] t4) {
6 | short[] t = new short[t1.length + t2.length + t3.length + t4.length];
7 | int index = 0;
8 | System.arraycopy(t1, 0, t, index, t1.length);
9 | index += t1.length;
10 | System.arraycopy(t2, 0, t, index, t2.length);
11 | index += t2.length;
12 | System.arraycopy(t3, 0, t, index, t3.length);
13 | index += t3.length;
14 | System.arraycopy(t4, 0, t, index, t4.length);
15 | return t;
16 | }
17 |
18 | public static final short[] yyTable() {
19 | return combine(yyTable1(), yyTable2(), yyTable3(), yyTable4());
20 | }
21 |
22 | public static final short[] yyCheck() {
23 | return combine(yyCheck1(), yyCheck2(), yyCheck3(), yyCheck4());
24 | }
25 | private static final short[] yyTable1() {
26 | return new short[] {
27 |
28 | };
29 | }
30 |
31 | private static final short[] yyTable2() {
32 | return new short[] {
33 |
34 | };
35 | }
36 |
37 | private static final short[] yyTable3() {
38 | return new short[] {
39 |
40 | };
41 | }
42 |
43 | private static final short[] yyTable4() {
44 | return new short[] {
45 |
46 | };
47 | }
48 |
49 | private static final short[] yyCheck1() {
50 | return new short[] {
51 |
52 | };
53 | }
54 |
55 | private static final short[] yyCheck2() {
56 | return new short[] {
57 |
58 | };
59 | }
60 |
61 | private static final short[] yyCheck3() {
62 | return new short[] {
63 |
64 | };
65 | }
66 |
67 | private static final short[] yyCheck4() {
68 | return new short[] {
69 |
70 | };
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/rewriter/ClassBodyWriter.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.rewriter;
2 |
3 | import java.util.Iterator;
4 |
5 | import org.jrubyparser.ast.BlockNode;
6 | import org.jrubyparser.ast.NewlineNode;
7 | import org.jrubyparser.ast.Node;
8 | import org.jrubyparser.rewriter.utils.ReWriterContext;
9 |
10 |
11 | public class ClassBodyWriter {
12 | private ReWriteVisitor visitor;
13 | private Node bodyNode;
14 | private ReWriterContext context;
15 |
16 | public ClassBodyWriter(ReWriteVisitor visitor, Node bodyNode) {
17 | this.visitor = visitor;
18 | this.bodyNode = bodyNode;
19 | this.context = visitor.getConfig();
20 | }
21 |
22 | public void write(){
23 | if (bodyNode instanceof BlockNode) {
24 | context.getIndentor().indent();
25 | writeContent((BlockNode) bodyNode);
26 | context.getIndentor().outdent();
27 | } else if (bodyNode instanceof NewlineNode) {
28 | visitor.visitNodeInIndentation(bodyNode);
29 | } else {
30 | visitor.visitNode(bodyNode);
31 | }
32 | }
33 |
34 | private void writeContent(BlockNode node) {
35 | for (Iterator it = node.childNodes().iterator(); it.hasNext(); ) {
36 | visitor.visitNode(it.next());
37 |
38 | if (it.hasNext()) {
39 | context.getOutput().print(context.getFormatHelper().classBodyElementsSeparator());
40 | }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/rewriter/FormatHelper.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.rewriter;
2 |
3 | import org.jrubyparser.rewriter.utils.Indenter;
4 |
5 | public interface FormatHelper {
6 |
7 | public abstract Indenter getIndenter();
8 |
9 | public abstract String getListSeparator();
10 |
11 | public abstract String beforeCallArguments();
12 |
13 | public abstract String afterCallArguments();
14 |
15 | public abstract String beforeMethodArguments();
16 |
17 | public abstract String afterMethodArguments();
18 |
19 | public abstract String hashAssignment();
20 |
21 | public abstract String beforeHashContent();
22 |
23 | public abstract String afterHashContent();
24 |
25 | public abstract String matchOperator();
26 |
27 | public abstract String beforeAssignment();
28 |
29 | public abstract String beforeIterBrackets();
30 |
31 | public abstract String afterAssignment();
32 |
33 | public abstract String beforeIterVars();
34 |
35 | public abstract String afterIterVars();
36 |
37 | public abstract String beforeClosingIterBrackets();
38 |
39 | public abstract String classBodyElementsSeparator();
40 |
41 | public abstract String getLineDelimiter();
42 | }
43 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/rewriter/utils/BooleanStateStack.java:
--------------------------------------------------------------------------------
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) 2006 Mirko Stocker
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 |
29 | package org.jrubyparser.rewriter.utils;
30 |
31 | import java.util.EmptyStackException;
32 | import java.util.Stack;
33 |
34 | public class BooleanStateStack {
35 |
36 | private final Stack states = new Stack();
37 | private final boolean defaultValue;
38 |
39 |
40 | public BooleanStateStack(boolean b, boolean defaultValue) {
41 | set(b);
42 | this.defaultValue = defaultValue;
43 | }
44 |
45 | public void set(boolean b) {
46 | states.push(Boolean.valueOf(b));
47 | }
48 |
49 | public void revert() {
50 | states.pop();
51 | }
52 |
53 | public boolean isTrue() {
54 | try {
55 | return ((Boolean) states.peek()).booleanValue();
56 | } catch (EmptyStackException e) {
57 | return defaultValue;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/rewriter/utils/CallDepth.java:
--------------------------------------------------------------------------------
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) 2006 Mirko Stocker
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 |
29 | package org.jrubyparser.rewriter.utils;
30 |
31 | public class CallDepth {
32 | private int nestedCallDepth;
33 | private int savedNestedCallDepth;
34 |
35 | public void enterCall() {
36 | nestedCallDepth++;
37 | }
38 |
39 | public void leaveCall() {
40 | nestedCallDepth--;
41 | if (nestedCallDepth < 0) nestedCallDepth = 0;
42 | }
43 |
44 | public boolean inCall() {
45 | return nestedCallDepth > 0;
46 | }
47 |
48 | /*
49 | * Those methods are used do disable the output of parantheses in arguments
50 | * of operator-calls
51 | */
52 | public void disableCallDepth() {
53 | savedNestedCallDepth = nestedCallDepth;
54 | nestedCallDepth = 0;
55 | }
56 |
57 | public void enableCallDepth() {
58 | nestedCallDepth = savedNestedCallDepth;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/rewriter/utils/DRegxReWriteVisitor.java:
--------------------------------------------------------------------------------
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) 2006 Mirko Stocker
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 |
29 | package org.jrubyparser.rewriter.utils;
30 |
31 | import org.jrubyparser.rewriter.ReWriteVisitor;
32 |
33 |
34 | public class DRegxReWriteVisitor extends ReWriteVisitor {
35 |
36 | public DRegxReWriteVisitor(ReWriterContext config) {
37 | super(config);
38 | }
39 |
40 | @Override
41 | protected boolean inDRegxNode() {
42 | return true;
43 | }
44 | }
--------------------------------------------------------------------------------
/src/org/jrubyparser/rewriter/utils/HereDocReWriteVisitor.java:
--------------------------------------------------------------------------------
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) 2006 Mirko Stocker
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 |
29 | package org.jrubyparser.rewriter.utils;
30 |
31 | import org.jrubyparser.ast.StrNode;
32 | import org.jrubyparser.rewriter.ReWriteVisitor;
33 |
34 | public class HereDocReWriteVisitor extends ReWriteVisitor {
35 |
36 | public HereDocReWriteVisitor(ReWriterContext config) {
37 | super(config);
38 | }
39 |
40 | @Override
41 | public Object visitStrNode(StrNode iVisited) {
42 | print(iVisited.getValue().toString());
43 | return null;
44 | }
45 | }
--------------------------------------------------------------------------------
/src/org/jrubyparser/rewriter/utils/HereDocument.java:
--------------------------------------------------------------------------------
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) 2006 Mirko Stocker
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 |
29 | package org.jrubyparser.rewriter.utils;
30 |
31 | public class HereDocument {
32 |
33 | public String content;
34 | private ReWriterContext config;
35 |
36 | public HereDocument(String content, ReWriterContext config) {
37 | super();
38 | this.content = content;
39 | this.config = config;
40 | }
41 |
42 | public String getContent() {
43 | return content;
44 | }
45 |
46 | public void print() {
47 | config.setSkipNextNewline(false);
48 | config.getOutput().print('\n');
49 | config.getOutput().print(getContent());
50 | config.getIndentor().printIndentation(config.getOutput());
51 | config.getOutput().print("EOF");
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/rewriter/utils/IgnoreCommentsReWriteVisitor.java:
--------------------------------------------------------------------------------
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) 2006 Mirko Stocker
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 |
29 | package org.jrubyparser.rewriter.utils;
30 |
31 | import org.jrubyparser.ast.CommentNode;
32 | import org.jrubyparser.rewriter.ReWriteVisitor;
33 |
34 | public class IgnoreCommentsReWriteVisitor extends ReWriteVisitor {
35 | public IgnoreCommentsReWriteVisitor(ReWriterContext config) {
36 | super(config);
37 | }
38 |
39 | @Override
40 | public Object visitCommentNode(CommentNode iVisited) {
41 | return null;
42 | }
43 | }
--------------------------------------------------------------------------------
/src/org/jrubyparser/rewriter/utils/LocalVariables.java:
--------------------------------------------------------------------------------
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) 2006 Mirko Stocker
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 |
29 | package org.jrubyparser.rewriter.utils;
30 |
31 | import java.util.HashMap;
32 |
33 | import org.jrubyparser.StaticScope;
34 |
35 | public class LocalVariables {
36 |
37 | private final HashMap localVariablesMap = new HashMap();
38 |
39 | public void addLocalVariable(int count, String name) {
40 | localVariablesMap.put(new Integer(count), name);
41 | }
42 |
43 | public void addLocalVariable(StaticScope scope) {
44 | for (int i = 0; i < scope.getVariables().length; i++) {
45 | addLocalVariable(i, scope.getVariables()[i]);
46 | }
47 | }
48 |
49 | public String getLocalVariable(int index) {
50 | return (String) localVariablesMap.get(new Integer(index));
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/rewriter/utils/MultipleAssignmentReWriteVisitor.java:
--------------------------------------------------------------------------------
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) 2006 Mirko Stocker
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 |
29 | package org.jrubyparser.rewriter.utils;
30 |
31 | import java.util.Iterator;
32 |
33 | import org.jrubyparser.ast.ArgumentNode;
34 | import org.jrubyparser.ast.Node;
35 | import org.jrubyparser.rewriter.ReWriteVisitor;
36 |
37 | public class MultipleAssignmentReWriteVisitor extends ReWriteVisitor {
38 |
39 | public MultipleAssignmentReWriteVisitor(ReWriterContext config) {
40 | super(config);
41 | }
42 |
43 | @Override
44 | protected void printAssignmentOperator() {
45 | }
46 |
47 | @Override
48 | protected boolean inMultipleAssignment() {
49 | return true;
50 | }
51 |
52 | // This might lead to a problem with comments
53 | @Override
54 | public void visitAndPrintWithSeparator(Iterator it) {
55 | while (it.hasNext()) {
56 | Node n = (Node) it.next();
57 | if(n instanceof ArgumentNode) {
58 | config.getOutput().print(((ArgumentNode) n).getName());
59 | } else {
60 | visitNode(n);
61 | }
62 | if (it.hasNext())
63 | print(", ");
64 | }
65 | }
66 | }
--------------------------------------------------------------------------------
/src/org/jrubyparser/rewriter/utils/Operators.java:
--------------------------------------------------------------------------------
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) 2006 Mirko Stocker
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 |
29 | package org.jrubyparser.rewriter.utils;
30 |
31 | import java.util.HashSet;
32 |
33 | public class Operators {
34 |
35 | private static HashSet operatorSet = new HashSet();
36 | static {
37 | String[] operators = new String[] { "**", "<=>", "==", "=~", "===", ">=", "<=", "&", "%",
38 | "/", "+", "-", "*", "<", ">", "<<", ">>", "|"};
39 |
40 | for(int i = 0; i < operators.length; i++) {
41 | operatorSet.add(operators[i]);
42 | }
43 | }
44 |
45 | public static boolean contain(String name) {
46 | return operatorSet.contains(name);
47 | }
48 | }
--------------------------------------------------------------------------------
/src/org/jrubyparser/rewriter/utils/ShortIfNodeReWriteVisitor.java:
--------------------------------------------------------------------------------
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) 2006 Mirko Stocker
15 | *
16 | * Alternatively, the contents of this file may be used under the terms of
17 | * either of the GNU General Public License Version 2 or later (the "GPL"),
18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 | * in which case the provisions of the GPL or the LGPL are applicable instead
20 | * of those above. If you wish to allow use of your version of this file only
21 | * under the terms of either the GPL or the LGPL, and not to allow others to
22 | * use your version of this file under the terms of the CPL, indicate your
23 | * decision by deleting the provisions above and replace them with the notice
24 | * and other provisions required by the GPL or the LGPL. If you do not delete
25 | * the provisions above, a recipient may use your version of this file under
26 | * the terms of any one of the CPL, the GPL or the LGPL.
27 | ***** END LICENSE BLOCK *****/
28 |
29 | package org.jrubyparser.rewriter.utils;
30 |
31 | import org.jrubyparser.ast.NewlineNode;
32 | import org.jrubyparser.rewriter.ReWriteVisitor;
33 |
34 | public class ShortIfNodeReWriteVisitor extends ReWriteVisitor {
35 |
36 | public ShortIfNodeReWriteVisitor(ReWriterContext config) {
37 | super(config);
38 | }
39 |
40 | @Override
41 | protected void printNewlineAndIndentation() {
42 | print("; ");
43 | }
44 |
45 | @Override
46 | public Object visitNewlineNode(NewlineNode iVisited) {
47 | if (config.getSource().charAt(getEndOffset(iVisited) - 1) == ')') {
48 | print('(');
49 | visitNode(iVisited.getNextNode());
50 | print(')');
51 | } else {
52 | print("; ");
53 | visitNode(iVisited.getNextNode());
54 | }
55 | return null;
56 | }
57 | }
--------------------------------------------------------------------------------
/src/org/jrubyparser/util/CStringBuilder.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.util;
2 |
3 | /**
4 | * The sole purpose of this builder is to allow append(int) do a forced cast to a char.
5 | * Our lexer returns int's for each character and builder till convert ints to base-10
6 | * decimal strings. This just makes things less error-prone
7 | */
8 | public class CStringBuilder implements CharSequence {
9 | private java.lang.StringBuilder builder;
10 |
11 | public CStringBuilder() {
12 | builder = new java.lang.StringBuilder();
13 | }
14 |
15 | public CStringBuilder(int capacity) {
16 | builder = new java.lang.StringBuilder(capacity);
17 | }
18 |
19 | public CStringBuilder(String initialValue) {
20 | builder = new java.lang.StringBuilder(initialValue);
21 | }
22 |
23 | /**
24 | * This will assume the passed in int is in fact a char.
25 | * @param value char to be consumed
26 | * @return the builder
27 | */
28 | public CStringBuilder append(int value) {
29 | builder.append((char) value);
30 |
31 | return this;
32 | }
33 |
34 | public CStringBuilder append(byte[] values) {
35 | builder.append(values);
36 |
37 | return this;
38 | }
39 |
40 | public CStringBuilder append(String value) {
41 | builder.append(value);
42 |
43 | return this;
44 | }
45 |
46 |
47 | public CStringBuilder append(boolean value) {
48 | builder.append(value);
49 |
50 | return this;
51 | }
52 |
53 | public CStringBuilder append(Object value) {
54 | builder.append(value);
55 |
56 | return this;
57 | }
58 |
59 | public int length() {
60 | return builder.length();
61 | }
62 |
63 | public String substring(int startIndex) {
64 | return builder.substring(startIndex);
65 | }
66 |
67 | public void setLength(int length) {
68 | builder.setLength(length);
69 | }
70 |
71 | @Override
72 | public String toString() {
73 | return builder.toString();
74 | }
75 |
76 | public char charAt(int index) {
77 | return builder.charAt(index);
78 | }
79 |
80 | public CharSequence subSequence(int start, int end) {
81 | return builder.subSequence(start, end);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/util/MethodDefVisitor.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.util;
2 |
3 | import org.jrubyparser.ast.*;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 |
9 | public class MethodDefVisitor extends NoopVisitor {
10 | private IModuleScope scope;
11 | private List list;
12 |
13 | public static List findMethodsIn(IModuleScope scope) {
14 | MethodDefVisitor visitor = new MethodDefVisitor(scope);
15 |
16 | visitor.run();
17 |
18 | return visitor.getMethodList();
19 | }
20 |
21 | public MethodDefVisitor(IModuleScope scope) {
22 | list = new ArrayList();
23 | this.scope = scope;
24 | }
25 |
26 | public void run() {
27 | for (Node child: ((Node) scope).childNodes()) {
28 | child.accept(this);
29 | }
30 | }
31 |
32 | public List getMethodList() {
33 | return list;
34 | }
35 |
36 | /*
37 | * nested blocks in blocks can have variables masked with same name so we make sure scope is correct.
38 | */
39 | private void addMethodIfInModule(MethodDefNode method) {
40 | if (method.getClosestModule() == scope ) list.add(method);
41 | }
42 |
43 |
44 | @Override
45 | public Object visitDefnNode(DefnNode iVisited) {
46 | addMethodIfInModule((MethodDefNode) iVisited);
47 | return null;
48 | }
49 |
50 | @Override
51 | public Object visitDefsNode(DefsNode iVisited) {
52 | addMethodIfInModule((MethodDefNode) iVisited);
53 | return null;
54 | }
55 |
56 |
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/org/jrubyparser/util/NodePair.java:
--------------------------------------------------------------------------------
1 | package org.jrubyparser.util;
2 |
3 | import org.jrubyparser.ast.Node;
4 |
5 | /**
6 | * Simple struct for holding a pair of nodes
7 | */
8 | public class NodePair {
9 | private final Node first;
10 | private final Node second;
11 |
12 | public NodePair(Node first, Node second) {
13 | this.first = first;
14 | this.second = second;
15 | }
16 |
17 | public Node getFirst() {
18 | return first;
19 | }
20 |
21 | public Node getSecond() {
22 | return second;
23 | }
24 |
25 | @Override
26 | public String toString() {
27 | return "NodePair: {" + getFirst() + ", " + getSecond() + "}";
28 | }
29 | }
30 |
--------------------------------------------------------------------------------