Class: Braingasm::Tokenizer
- Inherits:
-
Enumerator
- Object
- Enumerator
- Braingasm::Tokenizer
- Defined in:
- lib/braingasm/tokenizer.rb
Instance Attribute Summary collapse
-
#column_number ⇒ Object
readonly
Returns the value of attribute column_number.
-
#input ⇒ Object
Returns the value of attribute input.
-
#line_numer ⇒ Object
readonly
Returns the value of attribute line_numer.
Instance Method Summary collapse
-
#initialize(input) ⇒ Tokenizer
constructor
A new instance of Tokenizer.
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_number ⇒ Object (readonly)
Returns the value of attribute column_number.
6 7 8 |
# File 'lib/braingasm/tokenizer.rb', line 6 def column_number @column_number end |
#input ⇒ Object
Returns the value of attribute input.
5 6 7 |
# File 'lib/braingasm/tokenizer.rb', line 5 def input @input end |
#line_numer ⇒ Object (readonly)
Returns the value of attribute line_numer.
6 7 8 |
# File 'lib/braingasm/tokenizer.rb', line 6 def line_numer @line_numer end |