Class: Ibex::Frontend::SourceSpan
- Inherits:
-
Object
- Object
- Ibex::Frontend::SourceSpan
- Defined in:
- lib/ibex/frontend/source_span.rb,
sig/ibex/frontend/source_span.rbs
Overview
An immutable half-open byte span in one grammar source.
Instance Attribute Summary collapse
- #file ⇒ String readonly
- #finish ⇒ SourcePosition readonly
- #start ⇒ SourcePosition readonly
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #end_byte ⇒ Integer
-
#initialize(file:, start:, finish:) ⇒ SourceSpan
constructor
A new instance of SourceSpan.
- #length ⇒ Integer
- #start_byte ⇒ Integer
- #to_h ⇒ Hash[Symbol, Object?]
Constructor Details
#initialize(file:, start:, finish:) ⇒ SourceSpan
Returns a new instance of SourceSpan.
54 55 56 57 58 59 60 61 |
# File 'lib/ibex/frontend/source_span.rb', line 54 def initialize(file:, start:, finish:) raise ArgumentError, "span end precedes its start" if finish.byte_offset < start.byte_offset @file = file.dup.freeze @start = start @finish = finish freeze end |
Instance Attribute Details
#file ⇒ String (readonly)
49 50 51 |
# File 'lib/ibex/frontend/source_span.rb', line 49 def file @file end |
#finish ⇒ SourcePosition (readonly)
51 52 53 |
# File 'lib/ibex/frontend/source_span.rb', line 51 def finish @finish end |
#start ⇒ SourcePosition (readonly)
50 51 52 |
# File 'lib/ibex/frontend/source_span.rb', line 50 def start @start end |
Instance Method Details
#empty? ⇒ Boolean
79 80 81 |
# File 'lib/ibex/frontend/source_span.rb', line 79 def empty? length.zero? end |
#end_byte ⇒ Integer
69 70 71 |
# File 'lib/ibex/frontend/source_span.rb', line 69 def end_byte finish.byte_offset end |
#length ⇒ Integer
74 75 76 |
# File 'lib/ibex/frontend/source_span.rb', line 74 def length end_byte - start_byte end |
#start_byte ⇒ Integer
64 65 66 |
# File 'lib/ibex/frontend/source_span.rb', line 64 def start_byte start.byte_offset end |
#to_h ⇒ Hash[Symbol, Object?]
84 85 86 |
# File 'lib/ibex/frontend/source_span.rb', line 84 def to_h { file: file, start: start.to_h, end: finish.to_h } end |