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.



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_columnObject (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_lineObject (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_charObject



20
21
22
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 20

def current_char
  input[@position]
end

#eof?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 16

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

#nextObject



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

#peekObject



24
25
26
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 24

def peek
  @input[@position + 1]
end

#peek_behindObject



28
29
30
# File 'lib/component_embedded_ruby/lexer/input_reader.rb', line 28

def peek_behind
  @input[@position - 1]
end