Module: Sourcify::Method::Parser::RawScanner::Extensions
Constant Summary
collapse
- Counter =
Common::Parser::RawScanner::Counter
Instance Method Summary
collapse
#codified_tokens, #data_frag, #offset_attributes, #preceded_with?, #process, #push, #push_comment, #push_dstring, #push_heredoc, #push_label
Instance Method Details
#construct_result_code ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/sourcify/lib/sourcify/method/parser/raw_scanner_extensions.rb', line 34
def construct_result_code
codes = [false, true].map do |fix_heredoc|
codified_tokens(fix_heredoc).force_encoding(@encoding)
end
begin
if valid?(codes[1]) && @body_matcher.call(codes[0])
@results << codes.map do |s|
s.sub(%r{^(def\s+)(?:[^\.]+\.)?(#{@name}.*end)$}m, '\1\2')
end
raise Escape if @stop_on_newline or @lineno != 1
reset_attributes
end
rescue Exception
raise if $!.is_a?(Escape)
end
end
|
#decrement_counter ⇒ Object
29
30
31
32
|
# File 'lib/sourcify/lib/sourcify/method/parser/raw_scanner_extensions.rb', line 29
def decrement_counter
@counter.decrement
construct_result_code if @counter.balanced?
end
|
#increment_counter(count = 1) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/sourcify/lib/sourcify/method/parser/raw_scanner_extensions.rb', line 21
def increment_counter(count = 1)
unless @counter.started?
return if (@rejecting_block = codified_tokens !~ @start_pattern)
offset_attributes
end
@counter.increment(count)
end
|
#increment_lineno ⇒ Object
12
13
14
15
|
# File 'lib/sourcify/lib/sourcify/method/parser/raw_scanner_extensions.rb', line 12
def increment_lineno
stop_if_probably_defined_by_proc
super
end
|
#reset_attributes ⇒ Object
54
55
56
57
|
# File 'lib/sourcify/lib/sourcify/method/parser/raw_scanner_extensions.rb', line 54
def reset_attributes
@counter = Counter.new
super
end
|
#stop_if_probably_defined_by_proc ⇒ Object
17
18
19
|
# File 'lib/sourcify/lib/sourcify/method/parser/raw_scanner_extensions.rb', line 17
def stop_if_probably_defined_by_proc
raise ProbablyDefinedByProc if @lineno == 1 && @results.empty? && !@counter.started?
end
|
#valid?(*args) ⇒ Boolean
59
60
61
62
|
# File 'lib/sourcify/lib/sourcify/method/parser/raw_scanner_extensions.rb', line 59
def valid?(*args)
args[0].start_with?('def') && super
end
|