Class: Antlr4ruby::CommonTokenStream

Inherits:
BufferedTokenStream show all
Defined in:
lib/antlr4ruby/common_token_stream.rb

Instance Method Summary collapse

Methods inherited from BufferedTokenStream

#consume, #fill, #get_hidden_tokens_to_left, #get_hidden_tokens_to_right, #get_multi, #get_text, #get_token_source, #get_tokens, #index, #la, #mark, #release, #seek, #set_token_source, #size

Constructor Details

#initialize(token_source, channel = Token::DEFAULT_CHANNEL) ⇒ CommonTokenStream

Returns a new instance of CommonTokenStream.



6
7
8
9
# File 'lib/antlr4ruby/common_token_stream.rb', line 6

def initialize(token_source, channel = Token::DEFAULT_CHANNEL)
  super(token_source)
  @channel = channel
end

Instance Method Details

#get_number_of_on_channel_tokensObject



50
51
52
53
54
55
56
57
58
# File 'lib/antlr4ruby/common_token_stream.rb', line 50

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

#lt(k) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/antlr4ruby/common_token_stream.rb', line 34

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