Class: Rematch::Source
- Inherits:
-
Object
- Object
- Rematch::Source
- 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
-
#index ⇒ Object
readonly
Returns the value of attribute index.
Instance Method Summary collapse
-
#initialize(source) ⇒ Source
constructor
A new instance of Source.
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
#index ⇒ Object (readonly)
Returns the value of attribute index.
9 10 11 |
# File 'lib/rematch/source.rb', line 9 def index @index end |