Class: DParse::Position
- Inherits:
-
Object
- Object
- DParse::Position
- Defined in:
- lib/d-parse/position.rb
Constant Summary collapse
- FAR_BEHIND =
new(index: -1, line: -1, column: -1)
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Instance Method Summary collapse
- #advance(char) ⇒ Object
-
#initialize(index: 0, line: 0, column: 0) ⇒ Position
constructor
A new instance of Position.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(index: 0, line: 0, column: 0) ⇒ Position
Returns a new instance of Position.
7 8 9 10 11 |
# File 'lib/d-parse/position.rb', line 7 def initialize(index: 0, line: 0, column: 0) @index = index @line = line @column = column end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
5 6 7 |
# File 'lib/d-parse/position.rb', line 5 def column @column end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
3 4 5 |
# File 'lib/d-parse/position.rb', line 3 def index @index end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
4 5 6 |
# File 'lib/d-parse/position.rb', line 4 def line @line end |
Instance Method Details
#advance(char) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/d-parse/position.rb', line 15 def advance(char) Position.new( index: @index + 1, line: char == "\n" ? @line + 1 : @line, column: char == "\n" ? 0 : @column + 1, ) end |
#inspect ⇒ Object
27 28 29 |
# File 'lib/d-parse/position.rb', line 27 def inspect "Pos(#{@index}; #{@line}:#{@column})" end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/d-parse/position.rb', line 23 def to_s "line #{@line + 1}, column #{@column + 1}" end |