Class: Otaku::Handler::Processor::MagicProc
Constant Summary
Constants inherited
from MagicProc
MagicProc::RUBY_2_RUBY, MagicProc::RUBY_PARSER
Instance Attribute Summary
Attributes inherited from MagicProc
#code, #file, #line
Instance Method Summary
collapse
Methods inherited from MagicProc
#eval!, #initialize, #marshal_dump, #marshal_load
Instance Method Details
#code_fragments ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/otaku/handler/processor.rb', line 26
def code_fragments
ignore, start_marker, arg =
[:ignore, :start_marker, :arg].map{|key| code_match_args[key] }
[
"proc #{start_marker} |#{arg}| ",
source_code.sub(ignore, '')
]
end
|
#code_match_args ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/otaku/handler/processor.rb', line 45
def code_match_args
@cache[:code_match_args] ||= (
arg_idx, marker_idx = 5, 3
args = source_code.match(code_regexp)
while args && prob_regexp =~ args[1]
arg_idx, marker_idx = 4, 2
args = source_code.match(revised_regexp(args[1]))
end
{
:ignore => args[1],
:start_marker => args[marker_idx],
:arg => args[arg_idx]
}
)
end
|
#code_regexp ⇒ Object
61
62
63
|
# File 'lib/otaku/handler/processor.rb', line 61
def code_regexp
/^(.*?(Otaku\.start.*?|lambda|proc|Proc\.new)\s*(do|\{)\s*(\|(\w+)\|\s*))/m
end
|
#prob_regexp ⇒ Object
69
70
71
|
# File 'lib/otaku/handler/processor.rb', line 69
def prob_regexp
/Otaku\.start.*?(lambda|proc|Proc\.new)\s*(\{|do)\s*\|\w+\|\s*$/m
end
|
#revised_regexp(e) ⇒ Object
65
66
67
|
# File 'lib/otaku/handler/processor.rb', line 65
def revised_regexp(e)
/^(.*?#{Regexp.quote(e)}.*?\s*(\{|do)\s*(\|(\w+)\|)\s*)/m
end
|
#sexp_regexp ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'lib/otaku/handler/processor.rb', line 35
def sexp_regexp
@cache[:sexp_regexp] ||= (
Regexp.new([
Regexp.quote("s(:iter, s(:call, nil, :"),
"(proc|lambda)",
Regexp.quote(", s(:arglist)), s(:lasgn, :#{code_match_args[:arg]}), s("),
].join)
)
end
|