Class: Graphlyte::Lexing::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/graphlyte/lexing/location.rb

Overview

A source file location

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_pos, end_pos) ⇒ Location

Returns a new instance of Location.



15
16
17
18
# File 'lib/graphlyte/lexing/location.rb', line 15

def initialize(start_pos, end_pos)
  @start_pos = start_pos
  @end_pos = end_pos
end

Instance Attribute Details

#end_posObject (readonly)

Returns the value of attribute end_pos.



13
14
15
# File 'lib/graphlyte/lexing/location.rb', line 13

def end_pos
  @end_pos
end

#start_posObject (readonly)

Returns the value of attribute start_pos.



13
14
15
# File 'lib/graphlyte/lexing/location.rb', line 13

def start_pos
  @start_pos
end

Class Method Details

.eofObject



24
25
26
# File 'lib/graphlyte/lexing/location.rb', line 24

def self.eof
  new(nil, nil)
end

Instance Method Details

#==(other) ⇒ Object



32
33
34
# File 'lib/graphlyte/lexing/location.rb', line 32

def ==(other)
  other.is_a?(self.class) && to_s == other.to_s
end

#eof?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/graphlyte/lexing/location.rb', line 28

def eof?
  start_pos.nil?
end

#to(location) ⇒ Object



20
21
22
# File 'lib/graphlyte/lexing/location.rb', line 20

def to(location)
  self.class.new(start_pos, location.end_pos)
end

#to_sObject



36
37
38
39
40
# File 'lib/graphlyte/lexing/location.rb', line 36

def to_s
  return 'EOF' if eof?

  "#{start_pos}-#{end_pos}"
end