Class: RuboCop::AST::NodePattern::Compiler::Subcompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/ast/node_pattern/compiler/subcompiler.rb

Overview

Base class for subcompilers Implements visitor pattern

Doc on how this fits in the compiling process:

/docs/modules/ROOT/pages/node_pattern.adoc

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(compiler) ⇒ Subcompiler

Returns a new instance of Subcompiler.



15
16
17
18
# File 'lib/rubocop/ast/node_pattern/compiler/subcompiler.rb', line 15

def initialize(compiler)
  @compiler = compiler
  @node = nil
end

Class Attribute Details

.registryObject (readonly)

Returns the value of attribute registry.



40
41
42
# File 'lib/rubocop/ast/node_pattern/compiler/subcompiler.rb', line 40

def registry
  @registry
end

Instance Attribute Details

#compilerObject (readonly)

Returns the value of attribute compiler.



13
14
15
# File 'lib/rubocop/ast/node_pattern/compiler/subcompiler.rb', line 13

def compiler
  @compiler
end

Class Method Details

.inherited(base) ⇒ Object



47
48
49
50
51
# File 'lib/rubocop/ast/node_pattern/compiler/subcompiler.rb', line 47

def inherited(base)
  us = self
  base.class_eval { @registry = us.registry.dup }
  super
end

.method_added(method) ⇒ Object



42
43
44
45
# File 'lib/rubocop/ast/node_pattern/compiler/subcompiler.rb', line 42

def method_added(method)
  @registry[Regexp.last_match(1).to_sym] = method if method =~ /^visit_(.*)/
  super
end

Instance Method Details

#compile(node) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/rubocop/ast/node_pattern/compiler/subcompiler.rb', line 20

def compile(node)
  prev = @node
  @node = node
  do_compile
ensure
  @node = prev
end