Bond 0.9
C++ Bond Runtime Library API Documentation
Loading...
Searching...
No Matches
Bond::TokenStream Class Reference

An iterator over the contents of a TokenCollection. More...

#include <bond/compiler/tokenstream.h>

Public Member Functions

 TokenStream ()
 Constructs an empty TokenStream object. More...
 
 TokenStream (const Token *buffer, int length)
 Constructs a TokenStream object. More...
 
void SetBuffer (const Token *buffer, int length)
 Sets the underlying buffer of Token objects and resets the position of the stream. More...
 
void Reset ()
 Resets the position of the stream. More...
 
void Advance ()
 Increments the position of the stream by one. More...
 
const TokenNext ()
 Returns the next token in the stream and advances the position. More...
 
const TokenNextIf (Token::TokenType type)
 Returns the next token in the stream if it matches the given type, otherwise returns nullptr. More...
 
const TokenNextIf (const TokenTypeSet &typeSet)
 Returns the next token in the stream if it matches any of the given types, otherwise returns nullptr. More...
 
const TokenPeek () const
 Returns the next token in the stream without advancing the position. More...
 
const TokenPeekIf (Token::TokenType type) const
 Returns the next token in the stream if it matches the given type, otherwise returns nullptr. More...
 
const TokenPeekIf (const TokenTypeSet &typeSet) const
 Returns the next token in the stream if it matches any of the given types, otherwise returns nullptr. More...
 
void SkipTo (Token::TokenType type)
 Advances the position of the stream until a Token of the given type is encountered. If no such Token is encountered, the stream is advanced to the end. More...
 
void SkipTo (const TokenTypeSet &typeSet)
 Advances the position of the stream until a Token of one of the given types is encountered. If no such Token is encountered, the stream is advanced to the end. More...
 
int GetPosition () const
 Returns the current position of the stream. More...
 
void SetPosition (int index)
 Set the current position of the stream. More...
 
int GetLength () const
 Returns the total number of tokens in the stream. More...
 

Detailed Description

An iterator over the contents of a TokenCollection.

TokenStream has methods to return the next available Token, test whether the next Token is of a certain type, peek at the next Token and manipulate the position in the stream.

Constructor & Destructor Documentation

◆ TokenStream() [1/2]

Bond::TokenStream::TokenStream ( )
inline

Constructs an empty TokenStream object.

◆ TokenStream() [2/2]

Bond::TokenStream::TokenStream ( const Token buffer,
int  length 
)
inline

Constructs a TokenStream object.

Parameters
bufferA pointer to a buffer of Token objects over which the stream iterates..
lengthThe number of Tokens contained in the buffer.

Member Function Documentation

◆ Advance()

void Bond::TokenStream::Advance ( )
inline

Increments the position of the stream by one.

◆ GetLength()

int Bond::TokenStream::GetLength ( ) const
inline

Returns the total number of tokens in the stream.

◆ GetPosition()

int Bond::TokenStream::GetPosition ( ) const
inline

Returns the current position of the stream.

◆ Next()

const Token * Bond::TokenStream::Next ( )

Returns the next token in the stream and advances the position.

◆ NextIf() [1/2]

const Token * Bond::TokenStream::NextIf ( const TokenTypeSet typeSet)

Returns the next token in the stream if it matches any of the given types, otherwise returns nullptr.

Parameters
typeSetThe set of types against which the next Token is compared.

◆ NextIf() [2/2]

const Token * Bond::TokenStream::NextIf ( Token::TokenType  type)

Returns the next token in the stream if it matches the given type, otherwise returns nullptr.

Parameters
typeThe type against which the next Token is compared.

◆ Peek()

const Token * Bond::TokenStream::Peek ( ) const
inline

Returns the next token in the stream without advancing the position.

◆ PeekIf() [1/2]

const Token * Bond::TokenStream::PeekIf ( const TokenTypeSet typeSet) const

Returns the next token in the stream if it matches any of the given types, otherwise returns nullptr.

Parameters
typeSetThe set of types against which the next Token is compared.

◆ PeekIf() [2/2]

const Token * Bond::TokenStream::PeekIf ( Token::TokenType  type) const

Returns the next token in the stream if it matches the given type, otherwise returns nullptr.

Parameters
typeThe type against which the next Token is compared.

◆ Reset()

void Bond::TokenStream::Reset ( )
inline

Resets the position of the stream.

◆ SetBuffer()

void Bond::TokenStream::SetBuffer ( const Token buffer,
int  length 
)

Sets the underlying buffer of Token objects and resets the position of the stream.

Parameters
bufferA pointer to a buffer of Token objects that the stream iterates over.
lengthThe number of Tokens contained in the buffer.

◆ SetPosition()

void Bond::TokenStream::SetPosition ( int  index)
inline

Set the current position of the stream.

Parameters
indexThe position that the stream is set to.

◆ SkipTo() [1/2]

void Bond::TokenStream::SkipTo ( const TokenTypeSet typeSet)

Advances the position of the stream until a Token of one of the given types is encountered. If no such Token is encountered, the stream is advanced to the end.

Parameters
typeSetThe set of types against which the Tokens are compared.

◆ SkipTo() [2/2]

void Bond::TokenStream::SkipTo ( Token::TokenType  type)

Advances the position of the stream until a Token of the given type is encountered. If no such Token is encountered, the stream is advanced to the end.

Parameters
typeThe type against which the Tokens are compared.

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