Class: ComponentEmbeddedRuby::Lexer::InputReader
- Inherits:
-
Object
- Object
- ComponentEmbeddedRuby::Lexer::InputReader
- Defined in:
- lib/component_embedded_ruby/lexer/input_reader.rb
Instance Attribute Summary collapse
-
#current_column ⇒ Object
readonly
Returns the value of attribute current_column.
-
#current_line ⇒ Object
readonly
Returns the value of attribute current_line.
Instance Method Summary collapse
- #current_char ⇒ Object
- #eof? ⇒ Boolean
-
#initialize(input) ⇒ InputReader
constructor
A new instance of InputReader.
- #next ⇒ Object
- #peek ⇒ Object
- #peek_behind ⇒ Object
Constructor Details
#initialize(input) ⇒ InputReader
Returns a new instance of InputReader.
8 9 10 11 12 13 14 |
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 8 def initialize(input) @input = input.freeze @position = 0 @current_line = 1 @current_column = 1 end |
Instance Attribute Details
#current_column ⇒ Object (readonly)
Returns the value of attribute current_column.
6 7 8 |
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 6 def current_column @current_column end |
#current_line ⇒ Object (readonly)
Returns the value of attribute current_line.
6 7 8 |
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 6 def current_line @current_line end |
Instance Method Details
#current_char ⇒ Object
20 21 22 |
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 20 def current_char input[@position] end |
#eof? ⇒ Boolean
16 17 18 |
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 16 def eof? @position == @input.length end |
#next ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 32 def next if current_char == "\n" @current_line += 1 @current_column = 1 else @current_column += 1 end @position += 1 end |
#peek ⇒ Object
24 25 26 |
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 24 def peek @input[@position + 1] end |
#peek_behind ⇒ Object
28 29 30 |
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 28 def peek_behind @input[@position - 1] end |