Class: Graphlyte::Lexing::Location
- Inherits:
-
Object
- Object
- Graphlyte::Lexing::Location
- Defined in:
- lib/graphlyte/lexing/location.rb
Overview
A source file location
Instance Attribute Summary collapse
-
#end_pos ⇒ Object
readonly
Returns the value of attribute end_pos.
-
#start_pos ⇒ Object
readonly
Returns the value of attribute start_pos.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eof? ⇒ Boolean
-
#initialize(start_pos, end_pos) ⇒ Location
constructor
A new instance of Location.
- #to(location) ⇒ Object
- #to_s ⇒ Object
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_pos ⇒ Object (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_pos ⇒ Object (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
.eof ⇒ Object
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
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_s ⇒ Object
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 |