module volta.ir.tokenstream

Code Map

module volta.ir.tokenstream;

public import volta.ir.token;


//! Class used by the parser to read lexed tokens.
class TokenStream
{
public:
	errSink: ErrorSink;


public:
	//! Takes the token array, initializes mTokens and sets the current token
	//! to the first token.
	this(tokens: Token[], errSink: ErrorSink) { }
	//! Reset the stream.
	fn reset() { }
	//! Compares the current token's type against the given type.
	fn opEquals(type: TokenType) bool { }
	//! Compares from the current token and onwards type against the list of
	//! types.
	fn opEquals(types: scope (const(scope (TokenType)[])) i32 { }
	//! Returns the current token.
	fn peek() Token { }
	//! Returns the current token. Thorws: CompilerPanic on mIndex == 0.
	fn previous() Token { }
	//! Returns the token @n steps ahead. Will clamp @n to stream length.
	fn lookahead(n: size_t, eof: bool) Token { }
	//! Returns the token @n step behind the current token. Will cause a
	//! compiler panic if looking to far back.
	fn lookbehind(n: size_t) Token { }
	//! Returns the current position in the stream.
	fn save() size_t { }
	//! Restore the stream to the current index retrieved from save().
	fn restore(index: size_t) { }


protected:
	mTokens: Token[];
	mIndex: size_t;
}
class TokenStream

Class used by the parser to read lexed tokens.

this(tokens: Token[], errSink: ErrorSink)

Takes the token array, initializes mTokens and sets the current token to the first token.

fn reset()

Reset the stream.

Side-effects: Sets mIndex = 0.

fn opEquals(type: TokenType) bool

Compares the current token's type against the given type.

Side-effects: None.

fn opEquals(types: scope (const(scope (TokenType)[])) i32

Compares from the current token and onwards type against the list of types.

Side-effects: None.

fn peek() Token

Returns the current token.

Side-effects: None.

fn previous() Token

Returns the current token. Thorws: CompilerPanic on mIndex == 0.

Side-effects: None.

See also

  • lookbehind.

fn lookahead(n: size_t, eof: bool) Token

Returns the token @n steps ahead. Will clamp @n to stream length.

Side-effects: None.

fn lookbehind(n: size_t) Token

Returns the token @n step behind the current token. Will cause a compiler panic if looking to far back.

Throws: CompilerPanic on @n being larger then mIndex.

Side-effects: None.

fn save() size_t

Returns the current position in the stream.

Side-effects: None.

fn restore(index: size_t)

Restore the stream to the current index retrieved from save().

Side-effects: mIndex is set to index.