Class: Leftovers::AST::Builder

Inherits:
Parser::Builders::Default
  • Object
show all
Defined in:
lib/leftovers/ast/builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.node_class(type) ⇒ Object

rubocop:disable Metrics



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/leftovers/ast/builder.rb', line 12

def self.node_class(type) # rubocop:disable Metrics
  case type
  when :array then ArrayNode
  when :block then BlockNode
  when :casgn then CasgnNode
  when :const then ConstNode
  when :def then DefNode
  when :defs then DefsNode
  when :false then FalseNode
  when :hash then HashNode
  when :int, :float then NumericNode
  when :lvar, :ivar, :gvar, :cvar then VarNode
  when :ivasgn, :cvasgn, :gvasgn then VasgnNode
  when :module, :class then ModuleNode
  when :nil then NilNode
  when :send, :csend then SendNode
  when :str then StrNode
  when :sym then SymNode
  when :true then TrueNode
  else Node
  end
end

Instance Method Details

#n(type, children, source_map) ⇒ Object

leftovers:keep



8
9
10
# File 'lib/leftovers/ast/builder.rb', line 8

def n(type, children, source_map) # leftovers:keep
  self.class.node_class(type).new(type, children, location: source_map)
end

#string_value(token) ⇒ Object

Don’t complain about invalid strings This is called by ::Parser::AST internals



37
38
39
# File 'lib/leftovers/ast/builder.rb', line 37

def string_value(token) # leftovers:keep
  value(token)
end