ANTLR Support Libraries 2.7.1+
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
TokenBuffer Class Reference

#include <TokenBuffer.hpp>

Collaboration diagram for TokenBuffer:
Collaboration graph
[legend]

Public Member Functions

 TokenBuffer (TokenStream &input_)
 
virtual ~TokenBuffer ()
 
void reset (void)
 Reset the input buffer to empty state. More...
 
int LA (unsigned int i)
 
RefToken LT (unsigned int i)
 
unsigned int mark ()
 
void rewind (unsigned int mark)
 
void consume ()
 
virtual unsigned int entries () const
 Return the number of entries in the TokenBuffer. More...
 

Protected Attributes

TokenStreaminput
 Token source. More...
 
unsigned int nMarkers
 Number of active markers. More...
 
unsigned int markerOffset
 Additional offset used when markers are active. More...
 
unsigned int numToConsume
 Number of calls to consume() since last LA() or LT() call. More...
 
CircularQueue< RefTokenqueue
 Circular queue with Tokens. More...
 

Private Member Functions

void fill (unsigned int amount)
 
void syncConsume ()
 
 TokenBuffer (const TokenBuffer &other)
 
const TokenBufferoperator= (const TokenBuffer &other)
 

Detailed Description

A Stream of Token objects fed to the parser from a TokenStream that can be rewound via mark()/rewind() methods.

A dynamic array is used to buffer up all the input tokens. Normally, "k" tokens are stored in the buffer. More tokens may be stored during guess mode (testing syntactic predicate), or when LT(i>k) is referenced. Consumption of tokens is deferred. In other words, reading the next token is not done by conume(), but deferred until needed by LA or LT.

Todo:
: see if we can integrate this one with InputBuffer into one template or so.
See also
antlr.Token
antlr.TokenStream
antlr.TokenQueue

Constructor & Destructor Documentation

◆ TokenBuffer() [1/2]

TokenBuffer::TokenBuffer ( TokenStream inp)

Create a token buffer

A Stream of Token objects fed to the parser from a TokenStream that can be rewound via mark()/rewind() methods.

A dynamic array is used to buffer up all the input tokens. Normally, "k" tokens are stored in the buffer. More tokens may be stored during guess mode (testing syntactic predicate), or when LT(i>k) is referenced. Consumption of tokens is deferred. In other words, reading the next token is not done by conume(), but deferred until needed by LA or LT.

See also
antlr.Token
antlr.TokenStream
antlr.TokenQueueCreate a token buffer

◆ ~TokenBuffer()

TokenBuffer::~TokenBuffer ( void  )
virtual

◆ TokenBuffer() [2/2]

TokenBuffer::TokenBuffer ( const TokenBuffer other)
private

Member Function Documentation

◆ consume()

void TokenBuffer::consume ( )
inline

Mark another token for deferred consumption

◆ entries()

unsigned int TokenBuffer::entries ( ) const
virtual

Return the number of entries in the TokenBuffer.

Get number of non-consumed tokens.

◆ fill()

void TokenBuffer::fill ( unsigned int  amount)
private

Ensure that the token buffer is sufficiently full

◆ LA()

int TokenBuffer::LA ( unsigned int  i)

Get a lookahead token value

◆ LT()

RefToken TokenBuffer::LT ( unsigned int  i)

Get a lookahead token

◆ mark()

unsigned int TokenBuffer::mark ( )

Return an integer marker that can be used to rewind the buffer to its current state.

◆ operator=()

const TokenBuffer& TokenBuffer::operator= ( const TokenBuffer other)
private

◆ reset()

void TokenBuffer::reset ( void  )
inline

Reset the input buffer to empty state.

◆ rewind()

void TokenBuffer::rewind ( unsigned int  mark)

Rewind the token buffer to a marker.

Parameters
markMarker returned previously from mark()

◆ syncConsume()

void TokenBuffer::syncConsume ( )
inlineprivate

Sync up deferred consumption

Member Data Documentation

◆ input

TokenStream& TokenBuffer::input
protected

Token source.

◆ markerOffset

unsigned int TokenBuffer::markerOffset
protected

Additional offset used when markers are active.

◆ nMarkers

unsigned int TokenBuffer::nMarkers
protected

Number of active markers.

◆ numToConsume

unsigned int TokenBuffer::numToConsume
protected

Number of calls to consume() since last LA() or LT() call.

◆ queue

CircularQueue<RefToken> TokenBuffer::queue
protected

Circular queue with Tokens.


The documentation for this class was generated from the following files: