Class: Ibex::Runtime::LocationSpan
- Inherits:
-
Object
- Object
- Ibex::Runtime::LocationSpan
- Defined in:
- lib/json5/generated_parser.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
- #start ⇒ Object readonly
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.
34 35 36 37 38 39 |
# File 'lib/json5/generated_parser.rb', line 34 def initialize(start:, finish:, empty: false) @start = start @finish = finish @empty = empty freeze end |
Instance Attribute Details
#finish ⇒ Object (readonly)
31 32 33 |
# File 'lib/json5/generated_parser.rb', line 31 def finish @finish end |
#start ⇒ Object (readonly)
30 31 32 |
# File 'lib/json5/generated_parser.rb', line 30 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.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/json5/generated_parser.rb', line 45 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
72 |
# File 'lib/json5/generated_parser.rb', line 72 def column = location_value(@start, :column) |
#empty? ⇒ Boolean
Whether this is the zero-width span of an empty production.
61 62 63 |
# File 'lib/json5/generated_parser.rb', line 61 def empty? @empty end |
#end_column ⇒ Object
92 93 94 95 96 |
# File 'lib/json5/generated_parser.rb', line 92 def end_column return column if empty? location_value(@finish, :end_column) || location_value(@finish, :column) end |
#end_file ⇒ Object
78 79 80 81 82 |
# File 'lib/json5/generated_parser.rb', line 78 def end_file return file if empty? location_value(@finish, :end_file) || location_value(@finish, :file) end |
#end_line ⇒ Object
85 86 87 88 89 |
# File 'lib/json5/generated_parser.rb', line 85 def end_line return line if empty? location_value(@finish, :end_line) || location_value(@finish, :line) end |
#file ⇒ Object
66 |
# File 'lib/json5/generated_parser.rb', line 66 def file = location_value(@start, :file) |
#line ⇒ Object
69 |
# File 'lib/json5/generated_parser.rb', line 69 def line = location_value(@start, :line) |
#source_line ⇒ Object
75 |
# File 'lib/json5/generated_parser.rb', line 75 def source_line = location_value(@start, :source_line) |
#to_h ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/json5/generated_parser.rb', line 99 def to_h { file: file, line: line, column: column, end_file: end_file, end_line: end_line, end_column: end_column, empty: empty? } end |