Class: RKelly::Nodes::Node
- Inherits:
-
Object
- Object
- RKelly::Nodes::Node
show all
- Includes:
- Enumerable, Visitable, Visitors
- Defined in:
- lib/rkelly/nodes/node.rb
Direct Known Subclasses
BinaryNode, BracketAccessorNode, CommaNode, DotAccessorNode, ForInNode, ForNode, FunctionCallNode, FunctionExprNode, IfNode, LabelNode, NewExprNode, OpEqualNode, PostfixNode, PropertyNode, ResolveNode, TryNode, VarDeclNode
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Visitable
#accept
Constructor Details
#initialize(value) ⇒ Node
Returns a new instance of Node.
9
10
11
12
13
|
# File 'lib/rkelly/nodes/node.rb', line 9
def initialize(value)
@value = value
@comments = []
@filename = @line = nil
end
|
Instance Attribute Details
Returns the value of attribute comments.
8
9
10
|
# File 'lib/rkelly/nodes/node.rb', line 8
def
@comments
end
|
#filename ⇒ Object
Returns the value of attribute filename.
8
9
10
|
# File 'lib/rkelly/nodes/node.rb', line 8
def filename
@filename
end
|
#line ⇒ Object
Returns the value of attribute line.
8
9
10
|
# File 'lib/rkelly/nodes/node.rb', line 8
def line
@line
end
|
#value ⇒ Object
Returns the value of attribute value.
8
9
10
|
# File 'lib/rkelly/nodes/node.rb', line 8
def value
@value
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
=~
15
16
17
|
# File 'lib/rkelly/nodes/node.rb', line 15
def ==(other)
other.is_a?(self.class) && @value == other.value
end
|
#===(other) ⇒ Object
20
21
22
|
# File 'lib/rkelly/nodes/node.rb', line 20
def ===(other)
other.is_a?(self.class) && @value === other.value
end
|
#pointcut(pattern) ⇒ Object
Also known as:
/
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/rkelly/nodes/node.rb', line 24
def pointcut(pattern)
case pattern
when String
ast = RKelly::Parser.new.parse(pattern)
finder = ast.value.first.class.to_s =~ /StatementNode$/ ?
ast.value.first.value : ast.value.first
visitor = PointcutVisitor.new(finder)
else
visitor = PointcutVisitor.new(pattern)
end
visitor.accept(self)
visitor
end
|
#to_dots ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/rkelly/nodes/node.rb', line 49
def to_dots
visitor = DotVisitor.new
visitor.accept(self)
= <<-END
digraph g {
graph [ rankdir = "TB" ];
node [
fontsize = "16"
shape = "ellipse"
];
edge [ ];
END
nodes = visitor.nodes.map { |x| x.to_s }.join("\n")
counter = 0
arrows = visitor.arrows.map { |x|
s = "#{x} [\nid = #{counter}\n];"
counter += 1
s
}.join("\n")
"#{}\n#{nodes}\n#{arrows}\n}"
end
|
#to_real_sexp ⇒ Object
75
76
77
|
# File 'lib/rkelly/nodes/node.rb', line 75
def to_real_sexp
RealSexpVisitor.new.accept(self)
end
|
#to_sexp ⇒ Object
41
42
43
|
# File 'lib/rkelly/nodes/node.rb', line 41
def to_sexp
SexpVisitor.new.accept(self)
end
|