org.jaitools.jiffle.parser
Class MultiChannelTokenStream

java.lang.Object
  extended by org.antlr.runtime.BufferedTokenStream
      extended by org.jaitools.jiffle.parser.MultiChannelTokenStream
All Implemented Interfaces:
org.antlr.runtime.IntStream, org.antlr.runtime.TokenStream

public final class MultiChannelTokenStream
extends org.antlr.runtime.BufferedTokenStream

A TokenStream that can work with multiple active channels. Adapted from ANTLR's CommonTokenStream class.

Since:
0.1
Version:
$Id: MultiChannelTokenStream.java 1653 2011-06-16 10:23:02Z michael.bedward $
Author:
Michael Bedward

Field Summary
protected  java.util.List<java.lang.Integer> activeChannels
          The List of active channel indices.
 
Fields inherited from class org.antlr.runtime.BufferedTokenStream
lastMarker, p, range, tokens, tokenSource
 
Constructor Summary
MultiChannelTokenStream(org.antlr.runtime.TokenSource tokenSource)
          Creates a new stream with the default ANTLR channel active.
MultiChannelTokenStream(org.antlr.runtime.TokenSource tokenSource, int[] channels)
          Creates a new stream with the given channels active.
 
Method Summary
 void addActiveChannel(int channelNum)
          Adds a channel to those active.
 void consume()
           
 boolean isActiveChannel(int channelNum)
          Tests if a channel is active.
protected  org.antlr.runtime.Token LB(int k)
          Looks backwards for the kth token on any of the active channels.
 org.antlr.runtime.Token LT(int k)
          Looks forwards for the kth token on any of the active channels.
 void removeActiveChannel(int channelNum)
          Removes a channel from those active.
 void removeAllActiveChannels()
          Removes all active channels.
 void setTokenSource(org.antlr.runtime.TokenSource tokenSource)
           
protected  void setup()
          Positions the stream at the first token on an active channel.
protected  int skipOffTokenChannels(int pos)
          Gets the index of the next token on an active channel, starting from pos.
protected  int skipOffTokenChannelsReverse(int pos)
          Gets the index of the next token on an active channel, starting from pos and scanning backwards.
 
Methods inherited from class org.antlr.runtime.BufferedTokenStream
fetch, fill, get, get, getSourceName, getTokens, getTokens, getTokens, getTokens, getTokens, getTokenSource, index, LA, mark, range, release, reset, rewind, rewind, seek, size, sync, toString, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

activeChannels

protected final java.util.List<java.lang.Integer> activeChannels
The List of active channel indices. These should all be positive and less than 99 (used by ANTLR to flag its hidden token channel).

Constructor Detail

MultiChannelTokenStream

public MultiChannelTokenStream(org.antlr.runtime.TokenSource tokenSource)
Creates a new stream with the default ANTLR channel active.

Parameters:
tokenSource - a lexer

MultiChannelTokenStream

public MultiChannelTokenStream(org.antlr.runtime.TokenSource tokenSource,
                               int[] channels)
Creates a new stream with the given channels active.

Parameters:
tokenSource - a lexer
channels - active channel indices
Method Detail

consume

public void consume()
Specified by:
consume in interface org.antlr.runtime.IntStream
Overrides:
consume in class org.antlr.runtime.BufferedTokenStream

LB

protected org.antlr.runtime.Token LB(int k)
Looks backwards for the kth token on any of the active channels.

Overrides:
LB in class org.antlr.runtime.BufferedTokenStream
Parameters:
k - number of active-channel tokens to scan over
Returns:
the token

LT

public org.antlr.runtime.Token LT(int k)
Looks forwards for the kth token on any of the active channels.

Specified by:
LT in interface org.antlr.runtime.TokenStream
Overrides:
LT in class org.antlr.runtime.BufferedTokenStream
Parameters:
k - number of active-channel tokens to scan over
Returns:
the token

skipOffTokenChannels

protected int skipOffTokenChannels(int pos)
Gets the index of the next token on an active channel, starting from pos.

Parameters:
pos - start token index
Returns:
the token index

skipOffTokenChannelsReverse

protected int skipOffTokenChannelsReverse(int pos)
Gets the index of the next token on an active channel, starting from pos and scanning backwards.

Parameters:
pos - start token index
Returns:
the token index

setup

protected void setup()
Positions the stream at the first token on an active channel.

Overrides:
setup in class org.antlr.runtime.BufferedTokenStream

setTokenSource

public void setTokenSource(org.antlr.runtime.TokenSource tokenSource)
Overrides:
setTokenSource in class org.antlr.runtime.BufferedTokenStream

addActiveChannel

public void addActiveChannel(int channelNum)
Adds a channel to those active.

Parameters:
channelNum - the channel to add

removeActiveChannel

public void removeActiveChannel(int channelNum)
Removes a channel from those active. It is safe to call this method speculatively.

Parameters:
channelNum - the channel to remove

isActiveChannel

public boolean isActiveChannel(int channelNum)
Tests if a channel is active.

Parameters:
channelNum - the channel to test
Returns:
true if the channel is active; false otherwise

removeAllActiveChannels

public void removeAllActiveChannels()
Removes all active channels.



Copyright © 2011. All Rights Reserved.