Class: Antlr4::Runtime::CommonTokenStream

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

Constant Summary

Constants inherited from IntStream

IntStream::EOF, IntStream::UNKNOWN_SOURCE_NAME

Instance Attribute Summary

Attributes inherited from BufferedTokenStream

#token_source, #tokens

Instance Method Summary collapse

Methods inherited from BufferedTokenStream

#consume, #fetch, #fill, #filter_for_channel, #get, #get_list, #get_tokens2, #hidden_tokens_to_left, #hidden_tokens_to_left1, #hidden_tokens_to_right, #hidden_tokens_to_right2, #index, #la, #lazy_init, #mark, #next_token_on_channel, #previous_token_on_channel, #release, #reset, #seek, #setup, #size, #source_name, #sync, #text, #text2, #text3, #text4, #tokens1

Methods inherited from TokenStream

#get, #token_source

Methods inherited from IntStream

#consume, #index, #la, #mark, #release, #seek, #size, #source_name

Constructor Details

#initialize(token_source, channel = nil) ⇒ CommonTokenStream

Returns a new instance of CommonTokenStream


4
5
6
7
8
# File 'lib/antlr4/runtime/common_token_stream.rb', line 4

def initialize(token_source, channel = nil)
  super(token_source)
  @channel = Token::DEFAULT_CHANNEL
  @channel = channel unless channel.nil?
end

Instance Method Details

#adjust_seek_index(i) ⇒ Object


10
11
12
# File 'lib/antlr4/runtime/common_token_stream.rb', line 10

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

#lb(k) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/antlr4/runtime/common_token_stream.rb', line 14

def lb(k)
  return nil if k.zero? || (@ptr - k) < 0

  i = @ptr
  n = 1
  # find k good tokens looking backwards
  while n <= k && i > 0
    # skip off-channel tokens
    i = previous_token_on_channel(i - 1, @channel)
    n += 1
  end
  return nil if i < 0

  @tokens[i]
end

#lt(k) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/antlr4/runtime/common_token_stream.rb', line 30

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

  i = @ptr
  n = 1 # we know tokens[p] is a good one
  # find k good tokens
  while n < k
    # skip off-channel tokens, but make sure to not look past EOF
    i = next_token_on_channel(i + 1, @channel) if sync(i + 1)
    n += 1
  end
  #    if ( i>range ) range = i
  @tokens[i]
end

#number_of_on_channel_tokensObject


47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/antlr4/runtime/common_token_stream.rb', line 47

def number_of_on_channel_tokens
  n = 0
  fill
  i = 0
  while i < @tokens.size
    t = @tokens.get(i)
    n += 1 if t.channel == @channel
    break if t.type == Token::EOF

    i += 1
  end
  n
end