Class: ExcelFormulaParser::TokenStream

Inherits:
Object
  • Object
show all
Defined in:
lib/surpass/ExcelFormulaParser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ TokenStream

Returns a new instance of TokenStream.



443
444
445
446
447
448
449
# File 'lib/surpass/ExcelFormulaParser.rb', line 443

def initialize(input)
    @buffer = []
    @input = input
    @channel = nil

    @index = 0;
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



441
442
443
# File 'lib/surpass/ExcelFormulaParser.rb', line 441

def index
  @index
end

Instance Method Details

#consumeObject



477
478
479
480
# File 'lib/surpass/ExcelFormulaParser.rb', line 477

def consume
   look_ahead(1) # force a read from the input if necessary
   @index = @index + 1
end

#look_ahead(pos) ⇒ Object

returns a Token



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/surpass/ExcelFormulaParser.rb', line 452

def look_ahead(pos)
    offset = @index + pos - 1

    while @buffer[-1] != :EOF && @buffer.length < offset + 1
        token = @input.next_token
        if token == :EOF || token.channel == @channel
            @buffer << token
        end
    end

    offset = -1 if offset >= @buffer.length
    if offset < @buffer.length
        @buffer[offset]
    end
end

#markObject



468
469
470
471
# File 'lib/surpass/ExcelFormulaParser.rb', line 468

def mark
    @state = { :index => @index }
    return 0
end

#rewind(marker) ⇒ Object



473
474
475
# File 'lib/surpass/ExcelFormulaParser.rb', line 473

def rewind(marker)
    @index = @state[:index]
end