Module

_types

Core types for Kida template engine.

Defines the fundamental types used throughout the Kida pipeline:

Types:

  • Token: Single lexer output unit with type, value, and location
  • TokenType: Enum classifying token types (operators, literals, etc.)

Constants:

  • KEYWORDS: Frozenset of reserved words recognized by parser
  • PRECEDENCE: Dict mapping token types to operator precedence

Thread-Safety: All types are immutable (frozen dataclasses, enums) for safe concurrent access during template compilation.

Token Categories:

  • Delimiters:BLOCK_BEGIN,VARIABLE_BEGIN, etc.
  • Literals:STRING,INTEGER,FLOAT
  • Identifiers:NAME(variables, keywords)
  • Operators:ADD,SUB,MUL,EQ,AND, etc.
  • Punctuation:DOT,COMMA,PIPE,LPAREN, etc.
  • Special:EOF,DATA(raw text)

Example:

>>> from kida._types import Token, TokenType
>>> token = Token(TokenType.NAME, "user", lineno=1, col_offset=5)
>>> token.type == TokenType.NAME

True >>> token.value 'user'

Classes

TokenType 0
Classification of lexer tokens. Categories: - Delimiters: Block, variable, comment markers …

Classification of lexer tokens.

Categories:

  • Delimiters: Block, variable, comment markers
  • Literals: Strings, numbers, booleans
  • Identifiers: Names, keywords
  • Operators: Arithmetic, comparison, logical
  • Punctuation: Parentheses, brackets, dots
  • Special: EOF, whitespace, data (raw text)
Token 5
A single token from the lexer.

A single token from the lexer.

Attributes

Name Type Description
type TokenType

Classification of this token

value str

The actual text/value of the token

lineno int

1-based line number in source

col_offset int

0-based column offset in source Immutable by design for thread-safety.

Methods

Internal Methods 1
__repr__ 0 str
def __repr__(self) -> str
Returns
str