Class: Ibex::Frontend::SourceSpan
- Inherits:
-
Object
- Object
- Ibex::Frontend::SourceSpan
- Defined in:
- lib/ibex/frontend/source_span.rb
Overview
An immutable half-open byte span in one grammar source.
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
: String.
-
#finish ⇒ Object
readonly
: SourcePosition.
-
#start ⇒ Object
readonly
: SourcePosition.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #end_byte ⇒ Object
-
#initialize(file:, start:, finish:) ⇒ SourceSpan
constructor
A new instance of SourceSpan.
- #length ⇒ Object
- #start_byte ⇒ Object
- #to_h ⇒ 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 ⇒ Object (readonly)
: String
49 50 51 |
# File 'lib/ibex/frontend/source_span.rb', line 49 def file @file end |
#finish ⇒ Object (readonly)
: SourcePosition
51 52 53 |
# File 'lib/ibex/frontend/source_span.rb', line 51 def finish @finish end |
#start ⇒ Object (readonly)
: SourcePosition
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 ⇒ Object
69 70 71 |
# File 'lib/ibex/frontend/source_span.rb', line 69 def end_byte finish.byte_offset end |
#length ⇒ Object
74 75 76 |
# File 'lib/ibex/frontend/source_span.rb', line 74 def length end_byte - start_byte end |
#start_byte ⇒ Object
64 65 66 |
# File 'lib/ibex/frontend/source_span.rb', line 64 def start_byte start.byte_offset end |
#to_h ⇒ 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 |