Class: Braingasm::Tokenizer

Inherits:
Enumerator
  • Object
show all
Defined in:
lib/braingasm/tokenizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Tokenizer

Returns a new instance of Tokenizer.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/braingasm/tokenizer.rb', line 8

def initialize(input)
  @line_numer = 1
  @column_number = 0

  scanner = StringScanner.new(input)

  super() do |y|
    loop do
      line_numer, column_number = @line_numer, @column_number

      while scanner.skip(/\s/)
        if scanner.beginning_of_line?
          line_numer += 1
          column_number = 0
        else
          column_number += 1
        end
      end

      break if scanner.eos?

      column_number += 1
      @line_numer, @column_number = line_numer, column_number
      y << read_token(scanner)
    end
  end
end

Instance Attribute Details

#column_numberObject (readonly)

Returns the value of attribute column_number.



6
7
8
# File 'lib/braingasm/tokenizer.rb', line 6

def column_number
  @column_number
end

#inputObject

Returns the value of attribute input.



5
6
7
# File 'lib/braingasm/tokenizer.rb', line 5

def input
  @input
end

#line_numerObject (readonly)

Returns the value of attribute line_numer.



6
7
8
# File 'lib/braingasm/tokenizer.rb', line 6

def line_numer
  @line_numer
end