zyntex.parsing.syntax

class zyntex.parsing.syntax.FunctionDeclaration(name, body, return_type, params=None, is_public=False, is_extern=False, is_export=False)[source]

Represents a Zig function declaration.

class FunctionParam(name, type, is_comptime)[source]
is_comptime: bool
name: str
type: TypeNode
property body: str | None

Raw body of the function declaration. None if the function is declared with extern.

classmethod from_node(node)[source]
Return type:

FunctionDeclaration

property is_export: bool

True, if the function is declared with export.

property is_extern: bool

True, if the function is declared with extern.

static is_node_valid(node)[source]
Return type:

bool

property is_public: bool

Whether the function is marked as pub.

property name: str
property params: list[FunctionParam]

List of function parameters.

property return_type: TypeNode
class zyntex.parsing.syntax.INodeElement(*args, **kwargs)[source]

Base class for all Zig AST node wrappers.

abstractmethod classmethod from_node(node)[source]
abstractmethod static is_node_valid(node)[source]
Return type:

bool

class zyntex.parsing.syntax.LazyInit(node)[source]

Marker object that carries a PyASTNode to support lazy attribute init.

Instances of this class are stored on objects to indicate that the real attribute value should be computed later from the provided AST node.

class zyntex.parsing.syntax.TestDeclaration(name, body)[source]

Represents a Zig test declaration.

property body: str

Raw body of the test.

classmethod from_node(node)[source]
Return type:

TestDeclaration

static is_node_valid(node)[source]
Return type:

bool

property name: str | None

Test name, or None for anonymous tests (e.g. test { … }).

class zyntex.parsing.syntax.TypeNode(array_type=None, array_length=None, optional_type=None, pointer_type=None, type=None, is_const=False, is_error_union=False)[source]

A High-level wrapper for Zig Types.

Provides methods to check if a type is an array, optional, pointer, or constant, and to access related subtypes. Distinguishes between primitive and custom (user-defined) types.

class CustomType(value)[source]

Represents a non-primitive (user-defined) type name.

value: str
property absolute_type: CustomType | PrimitiveType

Resolve the absolute base type.

Walks through optional/array/pointer wrappers to locate the underlying identifier. Returns PrimitiveType for known primitives or CustomType for user-defined names. Raises NotImplementedError for unsupported type nodes.

property array_length: str | None

Declared length of the array. None if the type node is not an array.

The value is returned as a string because it may represent either a numeric literal or a symbolic name (variable/expression).

property array_type: TypeNode | None

Type node of the array, or None if not an array.

classmethod from_node(node)[source]
Return type:

TypeNode

is_array()[source]
Return type:

bool

property is_const: bool
property is_error_union: bool
static is_node_valid(node)[source]
Return type:

bool

is_optional()[source]
Return type:

bool

is_pointer()[source]
Return type:

bool

is_type()[source]
Return type:

bool

property optional_type: TypeNode | None

The inner type of optional, or None if not optional.

property pointer_type: TypeNode | None

The pointed-to type, or None if not a pointer.

property type: PrimitiveType | CustomType | None

Immediate type as PrimitiveType or CustomType, if identifier.

class zyntex.parsing.syntax.VariableDeclaration(name, value, type_hint, alignment=None, is_public=False, is_const=False, is_extern=False, is_export=False)[source]

Represents a Zig variable declaration.

property alignment: str | None

The explicit Zig alignment for the variable, if present.

classmethod from_node(node)[source]
Return type:

VariableDeclaration

property is_const: bool

Whether the variable is declared with const.

property is_export: bool

True, if the variable is declared with export.

property is_extern: bool

True, if the variable is declared with extern.

static is_node_valid(node)[source]
Return type:

bool

property is_public: bool

Whether the variable is marked as pub.

property name: str
property type_hint: TypeNode | None

The explicit Zig type annotation for the variable, if present.

property value: str | None

The raw value of the variable. None if the variable is declared with extern.

zyntex.parsing.syntax.lazy_invoke(func)[source]

A decorator for lazy properties.

Apply this to a @property method so its value is computed only on first access and then reused. The computed value is stored on a private attribute named _<property_name>. If that attribute is a LazyInit marker, the wrapped function will run to produce the value.