Class: Yoda::Parsing::SourceCutter
- Inherits:
-
Object
- Object
- Yoda::Parsing::SourceCutter
- Defined in:
- lib/yoda/parsing/source_cutter.rb
Overview
SourceCutter modifies the given source to fix parse errors around the location.
Defined Under Namespace
Classes: BlockFixer, CannotRecoverError, FixingSource, LineFixer
Instance Attribute Summary collapse
-
#current_location ⇒ Object
readonly
Returns the value of attribute current_location.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #current_location_token ⇒ (Symbol, (String, ::Parser::Source::Range))
- #current_location_token_index ⇒ Integer
- #current_location_token_range ⇒ ::Parser::Source::Range
-
#cut_position ⇒ Integer
The last point of cut source.
- #cut_source ⇒ String
-
#error_recovered_source ⇒ String
Returns a source that is made parsable from cut_source.
-
#initialize(source, current_location) ⇒ SourceCutter
constructor
A new instance of SourceCutter.
- #tokens_of_source ⇒ Array<(Symbol, (String, ::Parser::Source::Range))>
Constructor Details
#initialize(source, current_location) ⇒ SourceCutter
Returns a new instance of SourceCutter.
11 12 13 14 |
# File 'lib/yoda/parsing/source_cutter.rb', line 11 def initialize(source, current_location) @source = source @current_location = current_location end |
Instance Attribute Details
#current_location ⇒ Object (readonly)
Returns the value of attribute current_location.
7 8 9 |
# File 'lib/yoda/parsing/source_cutter.rb', line 7 def current_location @current_location end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
7 8 9 |
# File 'lib/yoda/parsing/source_cutter.rb', line 7 def source @source end |
Instance Method Details
#current_location_token ⇒ (Symbol, (String, ::Parser::Source::Range))
36 37 38 |
# File 'lib/yoda/parsing/source_cutter.rb', line 36 def current_location_token tokens_of_source[current_location_token_index] end |
#current_location_token_index ⇒ Integer
28 29 30 31 32 33 |
# File 'lib/yoda/parsing/source_cutter.rb', line 28 def current_location_token_index @current_location_token_index ||= begin reverse_index = tokens_of_source.reverse_each.find_index { |type, (name, range)| current_location.later_than?(range) } tokens_of_source.length - 1 - reverse_index end end |
#current_location_token_range ⇒ ::Parser::Source::Range
23 24 25 |
# File 'lib/yoda/parsing/source_cutter.rb', line 23 def current_location_token_range @current_location_token_range ||= current_location_token.last.last end |
#cut_position ⇒ Integer
The last point of cut source.
18 19 20 |
# File 'lib/yoda/parsing/source_cutter.rb', line 18 def cut_position @cut_position ||= current_location_token_range.end_pos - 1 end |
#cut_source ⇒ String
49 50 51 |
# File 'lib/yoda/parsing/source_cutter.rb', line 49 def cut_source @cut_source ||= source.slice(0..cut_position) end |
#error_recovered_source ⇒ String
Returns a source that is made parsable from cut_source.
55 56 57 |
# File 'lib/yoda/parsing/source_cutter.rb', line 55 def error_recovered_source @error_recovered_source ||= recover_source end |