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, untyped]
Constructor Details
#initialize(file:, start:, finish:) ⇒ SourceSpan
Returns a new instance of SourceSpan.
46 47 48 49 50 51 52 53 |
# File 'lib/ibex/frontend/source_span.rb', line 46 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)
41 42 43 |
# File 'lib/ibex/frontend/source_span.rb', line 41 def file @file end |
#finish ⇒ SourcePosition (readonly)
43 44 45 |
# File 'lib/ibex/frontend/source_span.rb', line 43 def finish @finish end |
#start ⇒ SourcePosition (readonly)
42 43 44 |
# File 'lib/ibex/frontend/source_span.rb', line 42 def start @start end |
Instance Method Details
#empty? ⇒ Boolean
71 72 73 |
# File 'lib/ibex/frontend/source_span.rb', line 71 def empty? length.zero? end |
#end_byte ⇒ Integer
61 62 63 |
# File 'lib/ibex/frontend/source_span.rb', line 61 def end_byte finish.byte_offset end |
#length ⇒ Integer
66 67 68 |
# File 'lib/ibex/frontend/source_span.rb', line 66 def length end_byte - start_byte end |
#start_byte ⇒ Integer
56 57 58 |
# File 'lib/ibex/frontend/source_span.rb', line 56 def start_byte start.byte_offset end |
#to_h ⇒ Hash[Symbol, untyped]
76 77 78 |
# File 'lib/ibex/frontend/source_span.rb', line 76 def to_h { file: file, start: start.to_h, end: finish.to_h } end |