Class: Sourcify::Proc::Parser::Normalizer
- Inherits:
-
Object
- Object
- Sourcify::Proc::Parser::Normalizer
- Defined in:
- lib/sourcify/proc/parser/normalizer.rb
Class Method Summary collapse
- .bounded_var?(var) ⇒ Boolean
- .fix_no_arg_method_calls(array) ⇒ Object
- .like_no_arg_method_call?(e) ⇒ Boolean
- .no_arg_method_call?(e) ⇒ Boolean
- .process(sexp, binding) ⇒ Object
Class Method Details
.bounded_var?(var) ⇒ Boolean
34 35 36 37 |
# File 'lib/sourcify/proc/parser/normalizer.rb', line 34 def bounded_var?(var) lvar = (@q ||= (IS_19x ? ":%s" : "'%s'")) % var @binding.has_local_variable?(lvar) end |
.fix_no_arg_method_calls(array) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sourcify/proc/parser/normalizer.rb', line 12 def fix_no_arg_method_calls(array) return array if [:class, :sclass, :defn, :module].include?(array[0]) array.map do |e| if e.is_a?(Array) no_arg_method_call?(e) or fix_no_arg_method_calls(e) else e end end end |
.like_no_arg_method_call?(e) ⇒ Boolean
29 30 31 32 |
# File 'lib/sourcify/proc/parser/normalizer.rb', line 29 def like_no_arg_method_call?(e) e.size == 4 && e[0..1] == [:call, nil] && e[3] == [:arglist] && (var = e[2]).is_a?(Symbol) end |
.no_arg_method_call?(e) ⇒ Boolean
23 24 25 26 27 |
# File 'lib/sourcify/proc/parser/normalizer.rb', line 23 def no_arg_method_call?(e) if like_no_arg_method_call?(e) bounded_var?(var = e[2]) ? [:lvar, var] : e end end |
.process(sexp, binding) ⇒ Object
7 8 9 10 |
# File 'lib/sourcify/proc/parser/normalizer.rb', line 7 def process(sexp, binding) @binding = binding Sexp.from_array(fix_no_arg_method_calls(sexp.to_a)) end |