Class: RuboCop::AST::Builder

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

Overview

‘RuboCop::Builder` is an AST builder that is utilized to let `Parser` generate ASTs with Node.

Examples:

buffer = Parser::Source::Buffer.new('(string)')
buffer.source = 'puts :foo'

builder = RuboCop::Builder.new
parser = Parser::CurrentRuby.new(builder)
root_node = parser.parse(buffer)

Constant Summary collapse

NODE_MAP =
{
  AndNode          => [:and],
  ArgsNode         => [:args],
  ArrayNode        => [:array],
  BlockNode        => [:block],
  CaseNode         => [:case],
  DefNode          => %i[def defs],
  EnsureNode       => [:ensure],
  ForNode          => [:for],
  HashNode         => [:hash],
  IfNode           => [:if],
  KeywordSplatNode => [:kwsplat],
  OrNode           => [:or],
  PairNode         => [:pair],
  RegexpNode       => [:regexp],
  ResbodyNode      => [:resbody],
  SendNode         => %i[csend send],
  SuperNode        => %i[super zsuper],
  UntilNode        => %i[until until_post],
  WhenNode         => [:when],
  WhileNode        => %i[while while_post],
  YieldNode        => [:yield]
}.freeze

Instance Method Summary collapse

Instance Method Details

#n(type, children, source_map) ⇒ Node

Generates Node from the given information.

Returns:

  • (Node)

    the generated node



43
44
45
# File 'lib/rubocop/ast/builder.rb', line 43

def n(type, children, source_map)
  node_klass(type).new(type, children, location: source_map)
end

#string_value(token) ⇒ Object

TODO: Figure out what to do about literal encoding handling… More details here github.com/whitequark/parser/issues/283



49
50
51
# File 'lib/rubocop/ast/builder.rb', line 49

def string_value(token)
  value(token)
end