Class: ANTLR3::ChainedTokenStream

Inherits:
Object
  • Object
show all
Includes:
TokenStream
Defined in:
lib/antlr3/token/linked.rb

Constant Summary

Constants included from Constants

ANTLR3::Constants::BUILT_IN_TOKEN_NAMES, ANTLR3::Constants::DEFAULT, ANTLR3::Constants::DOWN, ANTLR3::Constants::EOF, ANTLR3::Constants::EOF_TOKEN, ANTLR3::Constants::EOR_TOKEN_TYPE, ANTLR3::Constants::HIDDEN, ANTLR3::Constants::INVALID, ANTLR3::Constants::INVALID_TOKEN, ANTLR3::Constants::MEMO_RULE_FAILED, ANTLR3::Constants::MEMO_RULE_UNKNOWN, ANTLR3::Constants::MIN_TOKEN_TYPE, ANTLR3::Constants::SKIP_TOKEN, ANTLR3::Constants::UP

Instance Attribute Summary collapse

Attributes included from TokenStream

#channel, #last_marker, #position, #token_source

Attributes included from Stream

#size, #source_name

Instance Method Summary collapse

Methods included from TokenStream

#at, #to_s

Methods included from Stream

#index, #release, #rewind, #seek

Constructor Details

#initialize(token_source, options = {}, &filter) ⇒ ChainedTokenStream

Returns a new instance of ChainedTokenStream


90
91
92
93
94
95
96
# File 'lib/antlr3/token/linked.rb', line 90

def initialize( token_source, options = {}, &filter )
  @token_source = token_source
  @last_marker = nil
  @channel = options.fetch( :channel, DEFAULT_CHANNEL )
  @source_name = options.fetch( :source_name ) {  @token_source.source_name rescue nil }
  @cursor = @tail = @head = nil
end

Instance Attribute Details

#headObject (readonly)

Returns the value of attribute head


88
89
90
# File 'lib/antlr3/token/linked.rb', line 88

def head
  @head
end

#tailObject (readonly)

Returns the value of attribute tail


88
89
90
# File 'lib/antlr3/token/linked.rb', line 88

def tail
  @tail
end

Instance Method Details

#consumeObject


112
113
114
115
116
117
# File 'lib/antlr3/token/linked.rb', line 112

def consume
  @head or first_harvest
  @cursor.eof? and return( nil )
  prev, @cursor = @cursor, look( 2 )
  return( prev )
end

#look(k = 1) ⇒ Object


102
103
104
105
106
107
108
109
110
# File 'lib/antlr3/token/linked.rb', line 102

def look( k = 1 )
  @head or first_harvest
  case
  when k == 1 then @cursor
  when k > 1 then walk_foward( k - 1 )
  when k < 0 then walk_backward( -k )
  when k == 0 then nil
  end
end

#markObject


128
129
130
# File 'lib/antlr3/token/linked.rb', line 128

def mark
  @last_marker = @cursor
end

#peek(k = 1) ⇒ Object


98
99
100
# File 'lib/antlr3/token/linked.rb', line 98

def peek( k = 1 )
  return( ( t = look( k ) ) ? t.type : EOF )
end

#resetObject


119
120
121
122
123
124
125
126
# File 'lib/antlr3/token/linked.rb', line 119

def reset
  @cursor = @head or return( self )
  while @cursor and @cursor.channel != @channel
    @cursor = @cursor.next || fetch
  end
  @last_marker = nil
  return self
end