Class: ANTLR3::ChainedTokenStream
- Inherits:
-
Object
- Object
- ANTLR3::ChainedTokenStream
- Includes:
- TokenStream
- Defined in:
- lib/antlr3/token/linked.rb
Constant Summary
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_TOKEN, ANTLR3::Constants::INVALID_TOKEN_TYPE, 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)
-
- (Object) head
readonly
Returns the value of attribute head.
-
- (Object) tail
readonly
Returns the value of attribute tail.
Attributes included from TokenStream
#channel, #last_marker, #position, #token_source
Attributes included from Stream
Instance Method Summary (collapse)
- - (Object) consume
-
- (ChainedTokenStream) initialize(token_source, options = {}, &filter)
constructor
A new instance of ChainedTokenStream.
- - (Object) look(k = 1)
- - (Object) mark
- - (Object) peek(k = 1)
- - (Object) reset
Constructor Details
- (ChainedTokenStream) initialize(token_source, options = {}, &filter)
A new instance of ChainedTokenStream
90 91 92 93 94 95 96 |
# File 'lib/antlr3/token/linked.rb', line 90 def initialize( token_source, = {}, &filter ) @token_source = token_source @last_marker = nil @channel = .fetch( :channel, DEFAULT_CHANNEL ) @source_name = .fetch( :source_name ) { @token_source.source_name rescue nil } @cursor = @tail = @head = nil end |
Instance Attribute Details
- (Object) head (readonly)
Returns the value of attribute head
88 89 90 |
# File 'lib/antlr3/token/linked.rb', line 88 def head @head end |
- (Object) tail (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
- (Object) consume
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 |
- (Object) look(k = 1)
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 |
- (Object) mark
128 129 130 |
# File 'lib/antlr3/token/linked.rb', line 128 def mark @last_marker = @cursor end |
- (Object) peek(k = 1)
98 99 100 |
# File 'lib/antlr3/token/linked.rb', line 98 def peek( k = 1 ) return( ( t = look( k ) ) ? t.type : EOF ) end |
- (Object) reset
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 |