Class: Rematch::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/rematch/source.rb

Overview

Parses a Ruby source file to statically identify the context (path) and content of every line.

Constant Summary collapse

REMATCH_METHODS =
%w[assert_rematch store_assert_rematch
must_rematch to_rematch store_must_rematch store_to_rematch].freeze
IGNORED_TOKENS =
(REMATCH_METHODS + %w[expect value _]).freeze
DOT_TOKENS =
['.', '&.'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Source



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rematch/source.rb', line 16

def initialize(source)
  @source   = source
  @lines    = source.lines
  @index    = Hash.new { |h, k| h[k] = [] } # { lineno => [id1, id2, ...] }
  @context  = [] # Context stack
  @contexts = {} # { lineno => context_array }
  if (sexp = Ripper.sexp(@source))
    walk(sexp)
    build_index
  end
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



9
10
11
# File 'lib/rematch/source.rb', line 9

def index
  @index
end