Skip to content

Tokens

liquid2.token.TokenT dataclass

Bases: ABC

The base class for all tokens.

start abstractmethod property

start: int

The start position of this token.

stop abstractmethod property

stop: int

The end position of this token.

liquid2.token.TokenType

Bases: Enum

liquid2.token.BlockCommentToken dataclass

Bases: CommentToken

A token representing a block comment.

That's one with a start and end tag.

liquid2.token.CommentToken dataclass

Bases: TokenT

A token representing a comment.

liquid2.token.ContentToken dataclass

Bases: TokenT

A token representing template text content that is not markup.

liquid2.token.ErrorToken dataclass

Bases: TokenT

A token representing a syntax error found by the lexer.

start property

start: int

Return the start position of this token.

stop property

stop: int

Return the end position of this token.

liquid2.token.InlineCommentToken dataclass

Bases: CommentToken

A token representing an inline comment tag.

That's one with # as the tag name. Like {% # some comment %}.

liquid2.token.LinesToken dataclass

Bases: TokenT

A token representing line statements, where each line is a tag expression.

The built-in {% liquid %} tag is an example of a tag that uses line statements.

liquid2.token.OutputToken dataclass

Bases: TokenT

A token representing an output statement.

liquid2.token.PathToken dataclass

Bases: TokenT

A token representing the path to a variable.

liquid2.token.RangeToken dataclass

Bases: TokenT

A token representing a range expression.

For example, (1..3).

liquid2.token.RawToken dataclass

Bases: TokenT

A token representing raw content that should be treated as plain text.

liquid2.token.TagToken dataclass

Bases: TokenT

A token representing a tag.

This could be an inline tag, or the start or end of a block tag.

liquid2.token.Token dataclass

Bases: TokenT

A liquid expression token.

start property

start: int

Return the start position of this token.

stop property

stop: int

Return the end position of this token.

liquid2.token.is_comment_token

is_comment_token(token: TokenT) -> TypeGuard[CommentToken]

A CommentToken type guard.

liquid2.token.is_content_token

is_content_token(token: TokenT) -> TypeGuard[ContentToken]

A ContentToken type guard.

liquid2.token.is_lines_token

is_lines_token(token: TokenT) -> TypeGuard[LinesToken]

A LinesToken type guard.

liquid2.token.is_output_token

is_output_token(token: TokenT) -> TypeGuard[OutputToken]

An OutputToken type guard.

liquid2.token.is_path_token

is_path_token(token: TokenT) -> TypeGuard[PathToken]

A PathToken type guard.

liquid2.token.is_range_token

is_range_token(token: TokenT) -> TypeGuard[RangeToken]

A RangeToken type guard.

liquid2.token.is_raw_token

is_raw_token(token: TokenT) -> TypeGuard[RawToken]

A RawToken type guard.

liquid2.token.is_tag_token

is_tag_token(token: TokenT) -> TypeGuard[TagToken]

A TagToken type guard.

liquid2.token.is_token_type

is_token_type(
    token: TokenT, t: TokenType
) -> TypeGuard[Token]

A Token type guard.

liquid2.TokenStream

Step through a stream of tokens.

current

current() -> TokenT

Return the item at self[0] without advancing the iterator.

expect

expect(typ: TokenType) -> None

Raise a LiquidSyntaxError if the current token type doesn't match typ.

expect_eos

expect_eos() -> None

Raise a syntax error if we're not at the end of the stream.

expect_one_of

expect_one_of(*types: TokenType) -> None

Raise a LiquidSyntaxError if the current token type is not in types.

expect_tag

expect_tag(tag_name: str) -> None

Raise a syntax error if the current token is not a tag with tag_name.

into_inner

into_inner() -> TokenStream

Return a new stream over the current token's expression, consuming the token.

RAISES DESCRIPTION
LiquidSyntaxError

if the current token is not a tag

is_tag

is_tag(tag_name: str) -> bool

Return True if the current token is a tag named tag_name.

next

next() -> TokenT

Return the next token and advance the iterator.

peek

peek() -> TokenT

Return the item at self[1] without advancing the iterator.