Class: ComponentEmbeddedRuby::Lexer::InputReader

Inherits:
Object
  • Object
show all
Defined in:
lib/component_embedded_ruby/lexer/input_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ InputReader

Returns a new instance of InputReader.



6
7
8
9
10
11
12
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 6

def initialize(input)
  @input = input.freeze
  @position = 0

  @current_line = 0
  @current_column = 0
end

Instance Attribute Details

#current_columnObject (readonly)

Returns the value of attribute current_column.



4
5
6
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 4

def current_column
  @current_column
end

#current_lineObject (readonly)

Returns the value of attribute current_line.



4
5
6
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 4

def current_line
  @current_line
end

Instance Method Details

#current_charObject



18
19
20
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 18

def current_char
  input[@position]
end

#eof?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 14

def eof?
  @position == @input.length
end

#nextObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 30

def next
  if current_char == "\n"
    @current_line += 1
    @current_column = 0
  else
    @current_column += 1
  end

  @position += 1
end

#peekObject



22
23
24
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 22

def peek
  @input[@position + 1]
end

#peek_behindObject



26
27
28
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 26

def peek_behind
  @input[@position - 1]
end