Class: Ibex::Frontend::SourcePosition
- Inherits:
-
Object
- Object
- Ibex::Frontend::SourcePosition
- Defined in:
- lib/ibex/frontend/source_span.rb
Overview
An immutable position in grammar source.
Instance Attribute Summary collapse
-
#byte_offset ⇒ Object
readonly
: Integer.
-
#column ⇒ Object
readonly
: Integer.
-
#line ⇒ Object
readonly
: Integer.
Instance Method Summary collapse
-
#initialize(byte_offset:, line:, column:) ⇒ SourcePosition
constructor
A new instance of SourcePosition.
- #to_h ⇒ Object
Constructor Details
#initialize(byte_offset:, line:, column:) ⇒ SourcePosition
Returns a new instance of SourcePosition.
31 32 33 34 35 36 37 38 39 |
# File 'lib/ibex/frontend/source_span.rb', line 31 def initialize(byte_offset:, line:, column:) raise ArgumentError, "byte_offset must be non-negative" if byte_offset.negative? raise ArgumentError, "line and column must be positive" unless line.positive? && column.positive? @byte_offset = byte_offset @line = line @column = column freeze end |
Instance Attribute Details
#byte_offset ⇒ Object (readonly)
: Integer
26 27 28 |
# File 'lib/ibex/frontend/source_span.rb', line 26 def byte_offset @byte_offset end |
#column ⇒ Object (readonly)
: Integer
28 29 30 |
# File 'lib/ibex/frontend/source_span.rb', line 28 def column @column end |
#line ⇒ Object (readonly)
: Integer
27 28 29 |
# File 'lib/ibex/frontend/source_span.rb', line 27 def line @line end |
Instance Method Details
#to_h ⇒ Object
42 43 44 |
# File 'lib/ibex/frontend/source_span.rb', line 42 def to_h { byte_offset: byte_offset, line: line, column: column } end |