class documentation

class TokenStream: (source)

View In Hierarchy

A token stream is an iterable that yields :class:`Token`\s. The parser however does not iterate over it but calls :meth:`next` to go one token ahead. The current active token is stored as :attr:`current`.

Method __bool__ Undocumented
Method __init__ Undocumented
Method __iter__ Undocumented
Method __next__ Go one token ahead and return the old one.
Method close Close the stream.
Method expect Expect a given token type and return it. This accepts the same argument as :meth:`jinja2.lexer.Token.test`.
Method look Look at the next token.
Method next_if Perform the token test and return the token if it matched. Otherwise the return value is `None`.
Method push Push a token back to the stream.
Method skip Got n tokens ahead.
Method skip_if Like :meth:`next_if` but only returns `True` or `False`.
Instance Variable closed Undocumented
Instance Variable current Undocumented
Instance Variable filename Undocumented
Instance Variable name Undocumented
Property eos Are we at the end of the stream?
Instance Variable _iter Undocumented
Instance Variable _pushed Undocumented
def __bool__(self): (source)

Undocumented

Returns
boolUndocumented
def __init__(self, generator, name, filename): (source)

Undocumented

Parameters
generator:t.Iterable[Token]Undocumented
name:t.Optional[str]Undocumented
filename:t.Optional[str]Undocumented
def __iter__(self): (source)

Undocumented

Returns
TokenStreamIteratorUndocumented
def __next__(self): (source)

Go one token ahead and return the old one. Use the built-in :func:`next` instead of calling this directly.

Returns
TokenUndocumented
def close(self): (source)

Close the stream.

def expect(self, expr): (source)

Expect a given token type and return it. This accepts the same argument as :meth:`jinja2.lexer.Token.test`.

Parameters
expr:strUndocumented
Returns
TokenUndocumented
def look(self): (source)

Look at the next token.

Returns
TokenUndocumented
def next_if(self, expr): (source)

Perform the token test and return the token if it matched. Otherwise the return value is `None`.

Parameters
expr:strUndocumented
Returns
t.Optional[Token]Undocumented
def push(self, token): (source)

Push a token back to the stream.

Parameters
token:TokenUndocumented
def skip(self, n=1): (source)

Got n tokens ahead.

Parameters
n:intUndocumented
def skip_if(self, expr): (source)

Like :meth:`next_if` but only returns `True` or `False`.

Parameters
expr:strUndocumented
Returns
boolUndocumented
closed: bool = (source)

Undocumented

current = (source)

Undocumented

filename = (source)

Undocumented

name = (source)

Undocumented

Are we at the end of the stream?

_iter = (source)

Undocumented

_pushed: te.Deque[Token] = (source)

Undocumented