class RuboCop::AST::Builder
`RuboCop::Builder` is an AST builder that is utilized to let `Parser` generate ASTs with {RuboCop::AST::Node}.
@example
buffer = Parser::Source::Buffer.new('(string)') buffer.source = 'puts :foo' builder = RuboCop::Builder.new parser = Parser::CurrentRuby.new(builder) root_node = parser.parse(buffer)
Constants
- NODE_MAP
Public Instance Methods
n(type, children, source_map)
click to toggle source
Generates {Node} from the given information.
@return [Node] the generated node
# File lib/rubocop/ast/builder.rb, line 42 def n(type, children, source_map) node_klass(type).new(type, children, location: source_map) end
string_value(token)
click to toggle source
TODO: Figure out what to do about literal encoding handling… More details here github.com/whitequark/parser/issues/283
# File lib/rubocop/ast/builder.rb, line 48 def string_value(token) value(token) end
Private Instance Methods
node_klass(type)
click to toggle source
# File lib/rubocop/ast/builder.rb, line 54 def node_klass(type) node_map[type] || Node end
node_map()
click to toggle source
Take the human readable constant and generate a hash map where each (mapped) node type is a key with its constant as the value.
# File lib/rubocop/ast/builder.rb, line 60 def node_map @node_map ||= begin NODE_MAP.each_pair.each_with_object({}) do |(klass, types), map| types.each { |type| map[type] = klass } end end end