Class: RKelly::Visitors::Visitor

Inherits:
Object
  • Object
show all
Defined in:
lib/rkelly/visitors/visitor.rb

Constant Summary collapse

TERMINAL_NODES =
%w{
  Break Continue EmptyStatement False Null Number Parameter Regexp Resolve
  String This True
}
SINGLE_VALUE_NODES =
%w{
  Parenthetical AssignExpr BitwiseNot Block Delete Element ExpressionStatement
  FunctionBody LogicalNot Return Throw TypeOf UnaryMinus UnaryPlus Void
}
BINARY_NODES =
%w{
  Add BitAnd BitOr BitXOr CaseClause Comma Divide DoWhile Equal Greater
  GreaterOrEqual In InstanceOf LeftShift Less LessOrEqual LogicalAnd
  LogicalOr Modulus Multiply NotEqual NotStrictEqual OpAndEqual
  OpDivideEqual OpEqual OpLShiftEqual OpMinusEqual OpModEqual
  OpMultiplyEqual OpOrEqual OpPlusEqual OpRShiftEqual OpURShiftEqual
  OpXOrEqual RightShift StrictEqual Subtract Switch UnsignedRightShift
  While With
}
ARRAY_VALUE_NODES =
%w{
  Arguments Array CaseBlock ConstStatement ObjectLiteral SourceElements
  VarStatement
}
NAME_VALUE_NODES =
%w{
  Label Property GetterProperty SetterProperty VarDecl
}
PREFIX_POSTFIX_NODES =
%w{ Postfix Prefix }
CONDITIONAL_NODES =
%w{ If Conditional }
FUNC_CALL_NODES =
%w{ NewExpr FunctionCall }
FUNC_DECL_NODES =
%w{ FunctionExpr FunctionDecl }
ALL_NODES =
%w{ For ForIn Try BracketAccessor DotAccessor } +
TERMINAL_NODES + SINGLE_VALUE_NODES + BINARY_NODES + ARRAY_VALUE_NODES +
NAME_VALUE_NODES + PREFIX_POSTFIX_NODES + CONDITIONAL_NODES +
FUNC_CALL_NODES + FUNC_DECL_NODES

Instance Method Summary collapse

Instance Method Details

#accept(target) ⇒ Object



37
38
39
# File 'lib/rkelly/visitors/visitor.rb', line 37

def accept(target)
  target.accept(self)
end

#visit_BracketAccessorNode(o) ⇒ Object



137
138
139
140
141
142
# File 'lib/rkelly/visitors/visitor.rb', line 137

def visit_BracketAccessorNode(o)
  [
    o.value.accept(self),
    o.accessor.accept(self)
  ]
end

#visit_DotAccessorNode(o) ⇒ Object



144
145
146
# File 'lib/rkelly/visitors/visitor.rb', line 144

def visit_DotAccessorNode(o)
  o.value.accept(self)
end

#visit_ForInNode(o) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/rkelly/visitors/visitor.rb', line 120

def visit_ForInNode(o)
  [
    o.left.accept(self),
    o.right.accept(self),
    o.value.accept(self)
  ]
end

#visit_ForNode(o) ⇒ Object



111
112
113
114
115
116
117
118
# File 'lib/rkelly/visitors/visitor.rb', line 111

def visit_ForNode(o)
  [
    o.init ? o.init.accept(self) : nil,
    o.test ? o.test.accept(self) : nil,
    o.counter ? o.counter.accept(self) : nil,
    o.value.accept(self)
  ]
end

#visit_TryNode(o) ⇒ Object



128
129
130
131
132
133
134
135
# File 'lib/rkelly/visitors/visitor.rb', line 128

def visit_TryNode(o)
  [
    o.value.accept(self),
    o.catch_var ? o.catch_var : nil,
    o.catch_block ? o.catch_block.accept(self) : nil,
    o.finally_block ? o.finally_block.accept(self) : nil
  ]
end