OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
antlr::InputBuffer Class Referenceabstract

A Stream of characters fed to the lexer from a InputStream that can be rewound via mark()/rewind() methods. More...

#include <InputBuffer.hpp>

+ Inheritance diagram for antlr::InputBuffer:

Public Member Functions

 InputBuffer ()
 Create a character buffer.
 
virtual void reset (void)
 Reset the input buffer to empty state.
 
void commit (void)
 This method updates the state of the input buffer so that the text matched since the most recent mark() is no longer held by the buffer.
 
virtual void consume ()
 Mark another character for deferred consumption.
 
virtual void fill (unsigned int amount)
 Ensure that the character buffer is sufficiently full.
 
virtual int getChar ()=0
 Override this in subclasses to get the next character.
 
virtual int LA (unsigned int i)
 Get a lookahead character.
 
virtual unsigned int mark ()
 Return an integer marker that can be used to rewind the buffer to its current state.
 
virtual bool isMarked () const
 Are there any marks active in the InputBuffer.
 
virtual void rewind (unsigned int mark)
 Rewind the character buffer to a marker.
 
virtual unsigned int entries () const
 Get the number of non-consumed characters.
 
std::string getLAChars () const
 get the current lookahead characters as a string
 
std::string getMarkedChars () const
 get the current marked characters as a string
 

Protected Member Functions

void syncConsume ()
 Sync up deferred consumption.
 

Protected Attributes

unsigned int nMarkers
 
unsigned int markerOffset
 
unsigned int numToConsume
 
CircularQueue< int > queue
 

Detailed Description

A Stream of characters fed to the lexer from a InputStream that can be rewound via mark()/rewind() methods.

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

See also
antlr.CharQueue

Definition at line 31 of file InputBuffer.hpp.

Constructor & Destructor Documentation

◆ InputBuffer()

antlr::InputBuffer::InputBuffer ( )
inline

Create a character buffer.

Definition at line 34 of file InputBuffer.hpp.

◆ ~InputBuffer()

virtual antlr::InputBuffer::~InputBuffer ( )
inlinevirtual

Definition at line 41 of file InputBuffer.hpp.

Member Function Documentation

◆ commit()

void antlr::InputBuffer::commit ( void )
inline

This method updates the state of the input buffer so that the text matched since the most recent mark() is no longer held by the buffer.

So, you either do a mark/rewind for failed predicate or mark/commit to keep on parsing without rewinding the input.

Definition at line 60 of file InputBuffer.hpp.

◆ consume()

virtual void antlr::InputBuffer::consume ( )
inlinevirtual

Mark another character for deferred consumption.

Definition at line 66 of file InputBuffer.hpp.

◆ entries()

unsigned int antlr::InputBuffer::entries ( ) const
virtual

Get the number of non-consumed characters.

Definition at line 79 of file InputBuffer.cpp.

◆ fill()

void antlr::InputBuffer::fill ( unsigned int amount)
virtual

Ensure that the character buffer is sufficiently full.

Definition at line 21 of file InputBuffer.cpp.

References getChar(), and syncConsume().

◆ getChar()

virtual int antlr::InputBuffer::getChar ( )
pure virtual

Override this in subclasses to get the next character.

Implemented in antlr::CharBuffer, and antlr::CharInputBuffer.

Referenced by fill().

◆ getLAChars()

std::string antlr::InputBuffer::getLAChars ( void ) const

get the current lookahead characters as a string

Warning
it may treat 0 and EOF values wrong

Definition at line 36 of file InputBuffer.cpp.

◆ getMarkedChars()

std::string antlr::InputBuffer::getMarkedChars ( void ) const

get the current marked characters as a string

Warning
it may treat 0 and EOF values wrong

Definition at line 49 of file InputBuffer.cpp.

◆ isMarked()

virtual bool antlr::InputBuffer::isMarked ( ) const
inlinevirtual

Are there any marks active in the InputBuffer.

Definition at line 89 of file InputBuffer.hpp.

◆ LA()

virtual int antlr::InputBuffer::LA ( unsigned int i)
inlinevirtual

Get a lookahead character.

Definition at line 78 of file InputBuffer.hpp.

◆ mark()

unsigned int antlr::InputBuffer::mark ( )
virtual

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

Definition at line 62 of file InputBuffer.cpp.

References syncConsume().

Referenced by rewind().

◆ reset()

virtual void antlr::InputBuffer::reset ( void )
inlinevirtual

Reset the input buffer to empty state.

Reimplemented in antlr::CharInputBuffer.

Definition at line 46 of file InputBuffer.hpp.

Referenced by antlr::CharInputBuffer::reset().

◆ rewind()

void antlr::InputBuffer::rewind ( unsigned int mark)
virtual

Rewind the character buffer to a marker.

Parameters
markMarker returned previously from mark()

Definition at line 72 of file InputBuffer.cpp.

References mark(), and syncConsume().

◆ syncConsume()

void antlr::InputBuffer::syncConsume ( )
inlineprotected

Sync up deferred consumption.

Definition at line 131 of file InputBuffer.hpp.

Referenced by fill(), mark(), and rewind().

Member Data Documentation

◆ markerOffset

unsigned int antlr::InputBuffer::markerOffset
protected

Definition at line 114 of file InputBuffer.hpp.

◆ nMarkers

unsigned int antlr::InputBuffer::nMarkers
protected

Definition at line 111 of file InputBuffer.hpp.

◆ numToConsume

unsigned int antlr::InputBuffer::numToConsume
protected

Definition at line 117 of file InputBuffer.hpp.

◆ queue

CircularQueue<int> antlr::InputBuffer::queue
protected

Definition at line 120 of file InputBuffer.hpp.


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