Class: Ibex::Frontend::SourcePosition

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/frontend/source_span.rb,
sig/ibex/frontend/source_span.rbs

Overview

An immutable position in grammar source.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(byte_offset:, line:, column:) ⇒ SourcePosition

Returns a new instance of SourcePosition.

RBS:

  • (byte_offset: Integer, line: Integer, column: Integer) -> void

Parameters:

  • byte_offset: (Integer)
  • line: (Integer)
  • column: (Integer)


23
24
25
26
27
28
29
30
31
# File 'lib/ibex/frontend/source_span.rb', line 23

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_offsetInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


18
19
20
# File 'lib/ibex/frontend/source_span.rb', line 18

def byte_offset
  @byte_offset
end

#columnInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


20
21
22
# File 'lib/ibex/frontend/source_span.rb', line 20

def column
  @column
end

#lineInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


19
20
21
# File 'lib/ibex/frontend/source_span.rb', line 19

def line
  @line
end

Instance Method Details

#to_hHash[Symbol, Integer]

RBS:

  • () -> Hash[Symbol, Integer]

Returns:

  • (Hash[Symbol, Integer])


34
35
36
# File 'lib/ibex/frontend/source_span.rb', line 34

def to_h
  { byte_offset: byte_offset, line: line, column: column }
end