Module: Sourcify::Proc::Parser::RawScanner::Extensions

Includes:
Common::Parser::RawScanner::Extensions
Included in:
Sourcify::Proc::Parser::RawScanner
Defined in:
lib/sourcify/lib/sourcify/proc/parser/raw_scanner_extensions.rb

Defined Under Namespace

Classes: BraceBlockCounter, DoEndBlockCounter

Instance Method Summary collapse

Methods included from Common::Parser::RawScanner::Extensions

#codified_tokens, #data_frag, #increment_lineno, #offset_attributes, #preceded_with?, #process, #push, #push_comment, #push_dstring, #push_heredoc, #push_label, #valid?

Instance Method Details

#construct_result_codeObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sourcify/lib/sourcify/proc/parser/raw_scanner_extensions.rb', line 44

def construct_result_code
  codes = [false, true].map do |fix_heredoc|
    %Q(proc #{codified_tokens(fix_heredoc)}).force_encoding(@encoding)
  end

  begin
    if valid?(codes[1]) && @body_matcher.call(codes[0])
      @results << codes
      raise Escape if @stop_on_newline or @lineno != 1
      reset_attributes
    end
  rescue Exception
    raise if $!.is_a?(Escape)
  end
end

#decrement_counter(key) ⇒ Object



30
31
32
33
34
# File 'lib/sourcify/lib/sourcify/proc/parser/raw_scanner_extensions.rb', line 30

def decrement_counter(key)
  return unless (counter = this_counter(key)).started?
  counter.decrement
  construct_result_code if counter.balanced?
end

#fix_counter_false_start(key) ⇒ Object



13
14
15
16
17
18
# File 'lib/sourcify/lib/sourcify/proc/parser/raw_scanner_extensions.rb', line 13

def fix_counter_false_start(key)
  return unless this_counter(key).just_started?
  return unless really_false_started?
  reset_attributes
  @tokens, @false_start_backup = @false_start_backup.dup, nil if @false_start_backup
end

#increment_counter(key, count = 1) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/sourcify/lib/sourcify/proc/parser/raw_scanner_extensions.rb', line 20

def increment_counter(key, count = 1)
  return if other_counter(key).started?
  unless (counter = this_counter(key)).started?
    return if (@rejecting_block = codified_tokens !~ @start_pattern)
    @false_start_backup = @tokens.dup if key == :brace
    offset_attributes
  end
  counter.increment(count)
end

#other_counter(type) ⇒ Object



36
37
38
# File 'lib/sourcify/lib/sourcify/proc/parser/raw_scanner_extensions.rb', line 36

def other_counter(type)
  {:do_end => @brace_counter, :brace => @do_end_counter}[type]
end

#really_false_started?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/sourcify/lib/sourcify/proc/parser/raw_scanner_extensions.rb', line 60

def really_false_started?
  valid?(%Q(#{codified_tokens(true)} 1}), :hash)
end

#reset_attributesObject



64
65
66
67
68
# File 'lib/sourcify/lib/sourcify/proc/parser/raw_scanner_extensions.rb', line 64

def reset_attributes
  @do_end_counter = DoEndBlockCounter.new
  @brace_counter = BraceBlockCounter.new
  super
end

#this_counter(type) ⇒ Object



40
41
42
# File 'lib/sourcify/lib/sourcify/proc/parser/raw_scanner_extensions.rb', line 40

def this_counter(type)
  {:brace => @brace_counter, :do_end => @do_end_counter}[type]
end