Class: RuboCop::AST::Builder

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

Overview

‘RuboCop::AST::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::AST::Builder.new
require 'parser/ruby25'
parser = Parser::Ruby25.new(builder)
root_node = parser.parse(buffer)

Constant Summary collapse

NODE_MAP =
{
  and:          AndNode,
  alias:        AliasNode,
  args:         ArgsNode,
  array:        ArrayNode,
  block:        BlockNode,
  numblock:     BlockNode,
  break:        BreakNode,
  case_match:   CaseMatchNode,
  case:         CaseNode,
  class:        ClassNode,
  def:          DefNode,
  defined?:     DefinedNode,
  defs:         DefNode,
  ensure:       EnsureNode,
  for:          ForNode,
  forward_args: ForwardArgsNode,
  float:        FloatNode,
  hash:         HashNode,
  if:           IfNode,
  int:          IntNode,
  irange:       RangeNode,
  erange:       RangeNode,
  kwsplat:      KeywordSplatNode,
  module:       ModuleNode,
  or:           OrNode,
  pair:         PairNode,
  regexp:       RegexpNode,
  resbody:      ResbodyNode,
  retry:        RetryNode,
  return:       ReturnNode,
  csend:        SendNode,
  send:         SendNode,
  str:          StrNode,
  dstr:         StrNode,
  xstr:         StrNode,
  sclass:       SelfClassNode,
  super:        SuperNode,
  zsuper:       SuperNode,
  sym:          SymbolNode,
  until:        UntilNode,
  until_post:   UntilNode,
  when:         WhenNode,
  while:        WhileNode,
  while_post:   WhileNode,
  yield:        YieldNode
}.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



68
69
70
# File 'lib/rubocop/ast/builder.rb', line 68

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



74
75
76
# File 'lib/rubocop/ast/builder.rb', line 74

def string_value(token)
  value(token)
end