Class: Simplabs::Excellent::Parsing::CodeProcessor

Inherits:
SexpProcessor
  • Object
show all
Defined in:
lib/simplabs/excellent/parsing/code_processor.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(checks) ⇒ CodeProcessor

Returns a new instance of CodeProcessor.



27
28
29
30
31
32
33
34
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 27

def initialize(checks)
  setup_checks(checks)
  setup_processors
  super()
  @require_empty = @warn_on_default = false
  @contexts = []
  @default_method = 'process_default'
end

Instance Method Details

#process(exp) ⇒ Object



36
37
38
39
40
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 36

def process(exp)
  super
rescue
  #continue on errors
end

#process_args(exp) ⇒ Object



90
91
92
93
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 90

def process_args(exp)
  exp[1..-1].each { |parameter| @contexts.last.parameters << parameter if parameter.is_a?(Symbol) }
  process_default(exp)
end

#process_call(exp) ⇒ Object



108
109
110
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 108

def process_call(exp)
  process_default(exp, CallContext.new(exp, @contexts.last))
end

#process_case(exp) ⇒ Object



100
101
102
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 100

def process_case(exp)
  process_default(exp, CaseContext.new(exp, @contexts.last))
end

#process_class(exp) ⇒ Object



42
43
44
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 42

def process_class(exp)
  process_default(exp, ClassContext.new(exp, @contexts.last))
end

#process_cvar(exp) ⇒ Object



62
63
64
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 62

def process_cvar(exp)
  process_default(exp, CvarContext.new(exp, @contexts.last))
end

#process_default(exp, context = nil) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 116

def process_default(exp, context = nil)
  @contexts.push(context) if context
  @contexts.each do |c|
    method = "process_#{exp.node_type}".to_sym
    c.send(method, exp) if c.respond_to?(method)
  end
  exp.children.each { |sub| process(sub) }
  apply_checks(exp)
  @contexts.pop if context
  exp
end

#process_defn(exp) ⇒ Object



50
51
52
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 50

def process_defn(exp)
  process_default(exp, MethodContext.new(exp, @contexts.last))
end

#process_defs(exp) ⇒ Object



54
55
56
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 54

def process_defs(exp)
  process_default(exp, SingletonMethodContext.new(exp, @contexts.last))
end

#process_for(exp) ⇒ Object



86
87
88
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 86

def process_for(exp)
  process_default(exp, ForLoopContext.new(exp, @contexts.last))
end

#process_gasgn(exp) ⇒ Object



70
71
72
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 70

def process_gasgn(exp)
  process_default(exp, GvarContext.new(exp, @contexts.last))
end

#process_gvar(exp) ⇒ Object



66
67
68
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 66

def process_gvar(exp)
  process_default(exp, GvarContext.new(exp, @contexts.last))
end

#process_if(exp) ⇒ Object



74
75
76
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 74

def process_if(exp)
  process_default(exp, IfContext.new(exp, @contexts.last))
end

#process_iter(exp) ⇒ Object



104
105
106
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 104

def process_iter(exp)
  process_default(exp, BlockContext.new(exp, @contexts.last))
end

#process_ivar(exp) ⇒ Object



58
59
60
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 58

def process_ivar(exp)
  process_default(exp, IvarContext.new(exp, @contexts.last))
end

#process_masgn(exp) ⇒ Object



95
96
97
98
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 95

def process_masgn(exp)
  exp[1][1..-1].each { |parameter| @contexts.last.parameters << parameter[1] if parameter[1].is_a?(Symbol) } if @contexts.last.is_a?(BlockContext)
  process_default(exp)
end

#process_module(exp) ⇒ Object



46
47
48
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 46

def process_module(exp)
  process_default(exp, ModuleContext.new(exp, @contexts.last))
end

#process_resbody(exp) ⇒ Object



112
113
114
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 112

def process_resbody(exp)
  process_default(exp, ResbodyContext.new(exp, @contexts.last))
end

#process_until(exp) ⇒ Object



82
83
84
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 82

def process_until(exp)
  process_default(exp, UntilContext.new(exp, @contexts.last))
end

#process_while(exp) ⇒ Object



78
79
80
# File 'lib/simplabs/excellent/parsing/code_processor.rb', line 78

def process_while(exp)
  process_default(exp, WhileContext.new(exp, @contexts.last))
end