Class: Ibex::Runtime::LocationSpan
- Inherits:
-
Object
- Object
- Ibex::Runtime::LocationSpan
- Defined in:
- lib/ibex/runtime/location_span.rb
Overview
The deterministic source span assigned to a reduced nonterminal.
Terminal stack entries retain the application-owned location object supplied by the lexer. A reduction wraps the outer boundaries in this immutable value so actions can distinguish synthesized spans.
Instance Attribute Summary collapse
-
#finish ⇒ Object
readonly
: untyped.
-
#start ⇒ Object
readonly
: untyped.
Class Method Summary collapse
-
.for_reduction(locations, lookahead:) ⇒ Object
Build a span for an LR reduction.
Instance Method Summary collapse
- #column ⇒ Object
-
#empty? ⇒ Boolean
Whether this is the zero-width span of an empty production.
- #end_column ⇒ Object
- #end_file ⇒ Object
- #end_line ⇒ Object
- #file ⇒ Object
-
#initialize(start:, finish:, empty: false) ⇒ LocationSpan
constructor
A new instance of LocationSpan.
- #line ⇒ Object
- #source_line ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(start:, finish:, empty: false) ⇒ LocationSpan
Returns a new instance of LocationSpan.
16 17 18 19 20 21 |
# File 'lib/ibex/runtime/location_span.rb', line 16 def initialize(start:, finish:, empty: false) @start = start @finish = finish @empty = empty freeze end |
Instance Attribute Details
#finish ⇒ Object (readonly)
: untyped
13 14 15 |
# File 'lib/ibex/runtime/location_span.rb', line 13 def finish @finish end |
#start ⇒ Object (readonly)
: untyped
12 13 14 |
# File 'lib/ibex/runtime/location_span.rb', line 12 def start @start end |
Class Method Details
.for_reduction(locations, lookahead:) ⇒ Object
Build a span for an LR reduction. Nonempty reductions cover the first through last located RHS entry. Empty reductions are zero-width at the current lookahead location.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ibex/runtime/location_span.rb', line 27 def self.for_reduction(locations, lookahead:) if locations.empty? return unless lookahead boundary = boundary_start(lookahead) return new(start: boundary, finish: boundary, empty: true) end located = locations.compact return if located.empty? new(start: boundary_start(located.first), finish: boundary_finish(located.last)) end |
Instance Method Details
#column ⇒ Object
54 |
# File 'lib/ibex/runtime/location_span.rb', line 54 def column = location_value(@start, :column) |
#empty? ⇒ Boolean
Whether this is the zero-width span of an empty production.
43 44 45 |
# File 'lib/ibex/runtime/location_span.rb', line 43 def empty? @empty end |
#end_column ⇒ Object
74 75 76 77 78 |
# File 'lib/ibex/runtime/location_span.rb', line 74 def end_column return column if empty? location_value(@finish, :end_column) || location_value(@finish, :column) end |
#end_file ⇒ Object
60 61 62 63 64 |
# File 'lib/ibex/runtime/location_span.rb', line 60 def end_file return file if empty? location_value(@finish, :end_file) || location_value(@finish, :file) end |
#end_line ⇒ Object
67 68 69 70 71 |
# File 'lib/ibex/runtime/location_span.rb', line 67 def end_line return line if empty? location_value(@finish, :end_line) || location_value(@finish, :line) end |
#file ⇒ Object
48 |
# File 'lib/ibex/runtime/location_span.rb', line 48 def file = location_value(@start, :file) |
#line ⇒ Object
51 |
# File 'lib/ibex/runtime/location_span.rb', line 51 def line = location_value(@start, :line) |
#source_line ⇒ Object
57 |
# File 'lib/ibex/runtime/location_span.rb', line 57 def source_line = location_value(@start, :source_line) |
#to_h ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/ibex/runtime/location_span.rb', line 81 def to_h { file: file, line: line, column: column, end_file: end_file, end_line: end_line, end_column: end_column, empty: empty? } end |