Sha256: 72358ef55c8a1a7bafd8363bdca6178b4ae77d495120d013b3a101092f7cf50e

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

# finished
require 'antlr4ruby/buffered_token_stream'

module Antlr4ruby
  class CommonTokenStream < BufferedTokenStream
    def initialize(token_source, channel = Token::DEFAULT_CHANNEL)
      super(token_source)
      @channel = channel
    end



    protected
    attr_accessor :channel

    def adjust_seek_index(i)
      next_token_on_channel(i, @channel)
    end

    def lb(k)
      return nil if k==0 || (@p -k) < 0

      i = @p
      n = 1
      while n <= k && i > 0
        i = previous_token_on_channel(i-1, @channel)
        n += 1
      end
      return nil if i < 0
      tokens[i]
    end

    public
    def lt(k)
      lazy_init
      return nil if k == 0
      return lb(-k) if k < 0

      i = @p
      n = 1
      while n < k
        if sync(i + 1)
          i = next_token_on_channel(i+1, channel)
        end
        n += 1
      end

      tokens[i]
    end
    def get_number_of_on_channel_tokens
      n = 0
      fill
      tokens.each do |token|
        n += 1 if token.get_channel == channel
        break if token.get_type == Token::EOF
      end
      n
    end


  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
antlr4ruby-0.1.0 lib/antlr4ruby/common_token_stream.rb