mjc

org.multijava.mjc
Class ParsingController.IndexedTokenBuffer

java.lang.Object
  extended byorg.multijava.mjc.ParsingController.IndexedTokenBuffer
Enclosing class:
ParsingController

class ParsingController.IndexedTokenBuffer
extends Object

This inner class buffers tokens of a nested language and allows selection and discarding of a subset of these buffered tokens based on a reference to an index token of the surrounding language.


Field Summary
private  LinkedList indexTokens
          A list of buffers containing index tokens of the surrounding language.
private  boolean isBlocked
          Indicates whether this is a blocked token buffer, to which new tokens or indices cannot be added.
private  boolean startNewBuffer
          Indicates whether a new buffer is required to store the next buffered token.
private  LinkedList tokenBuffers
          A list of token buffers.
 
Constructor Summary
ParsingController.IndexedTokenBuffer()
          Creates a new empty token buffer.
ParsingController.IndexedTokenBuffer(LinkedList tokenBuffers)
          Creates a blocked token buffer from the given list of token buffers.
 
Method Summary
private  void addEOF()
          Adds an end-of-file token to the end of the token buffer.
 void bufferToken(antlr.Token tok)
          Adds the given token of the nested language to the buffer.
private  int findIndexToken(antlr.Token index)
          Returns the position in tokenBuffers of the last contiguous block of buffered tokens that comes before the given index token.
 boolean flushTokensBefore(antlr.Token index)
          Discards all buffered tokens before the given index token.
 boolean hasNext()
          Returns true if this buffer has additional tokens.
 boolean isBlocked()
          Indicates whether this token buffer is blocked from accepting additinal tokens or indices.
 antlr.Token next()
          Returns the next token from the buffer.
 void recordIndexToken(antlr.Token index)
          Records the given index token.
 ParsingController.FilteredTokenStream streamForTokensBefore(antlr.Token index)
          Returns a token stream that includes just the buffered tokens that came before the given index token.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isBlocked

private boolean isBlocked
Indicates whether this is a blocked token buffer, to which new tokens or indices cannot be added.


startNewBuffer

private boolean startNewBuffer
Indicates whether a new buffer is required to store the next buffered token.


tokenBuffers

private LinkedList tokenBuffers
A list of token buffers. Each token buffer stored in this list contains a group of contiguous tokens from the original source text. Unless isBlocked, no token buffer stored in this list is empty.


indexTokens

private LinkedList indexTokens
A list of buffers containing index tokens of the surrounding language. Unless isBlocked, for all i, 0<=i
Constructor Detail

ParsingController.IndexedTokenBuffer

public ParsingController.IndexedTokenBuffer()
Creates a new empty token buffer.


ParsingController.IndexedTokenBuffer

public ParsingController.IndexedTokenBuffer(LinkedList tokenBuffers)
Creates a blocked token buffer from the given list of token buffers. A token buffer that is blocked does not accept new tokens or indices.

Method Detail

bufferToken

public void bufferToken(antlr.Token tok)
                 throws antlr.TokenStreamException
Adds the given token of the nested language to the buffer.

Throws:
antlr.TokenStreamException - if buffer is blocked

recordIndexToken

public void recordIndexToken(antlr.Token index)
                      throws antlr.TokenStreamException
Records the given index token.

Throws:
antlr.TokenStreamException - if buffer is blocked

streamForTokensBefore

public ParsingController.FilteredTokenStream streamForTokensBefore(antlr.Token index)
                                                            throws antlr.TokenStreamException
Returns a token stream that includes just the buffered tokens that came before the given index token. Removes those buffered tokens from this. If the index token is not recorded in this, then the stream returned will just contain an end-of-file token.

Throws:
antlr.TokenStreamException - if buffer is blocked

flushTokensBefore

public boolean flushTokensBefore(antlr.Token index)
                          throws antlr.TokenStreamException
Discards all buffered tokens before the given index token. If the index token is not recorded in this then no buffered tokens are discarded.

Returns:
true, iff some buffered tokens were discarded
Throws:
antlr.TokenStreamException - if buffer is blocked

isBlocked

public boolean isBlocked()
Indicates whether this token buffer is blocked from accepting additinal tokens or indices.


next

public antlr.Token next()
Returns the next token from the buffer.


hasNext

public boolean hasNext()
Returns true if this buffer has additional tokens. A buffer that is not blocked may return false and then return true on subsequent calls if tokens are added to the buffer.


findIndexToken

private int findIndexToken(antlr.Token index)
Returns the position in tokenBuffers of the last contiguous block of buffered tokens that comes before the given index token. Returns -1 if the index token is not recorded in this.


addEOF

private void addEOF()
Adds an end-of-file token to the end of the token buffer. Should only be called on a blocked buffer.


mjc

mjc is Copyright (C) 2000-2004 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. mjc is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.