zyntex.parsing.bindings

class zyntex.parsing.bindings.ASTNode[source]

Represents a node in the Zig AST.

index

Structure/Union member

main_token

Structure/Union member

property tag: NodeTag

The node tag as a NodeTag enum.

tag_index

Structure/Union member

class zyntex.parsing.bindings.ASTToken[source]

Represents a token in the Zig AST.

start

Structure/Union member

property tag: TokenTag

The token tag as a TokenTag enum.

tag_index

Structure/Union member

class zyntex.parsing.bindings.ErrorReport[source]

Represents a parsing error.

is_note

Structure/Union member

property tag: ErrorTag

The error tag as an ErrorTag enum.

tag_index

Structure/Union member

token_index

Structure/Union member

token_is_prev

Structure/Union member

class zyntex.parsing.bindings.ErrorTag(*values)[source]

Bindings to the Zig std.zig.Ast.Error.Tag enum. Ref: https://github.com/ziglang/zig/blob/0.15.1/lib/std/zig/Ast.zig#L2935

These enum values correspond to the error tag identifiers returned by the Zig parser. Used to indicate specific kinds of syntax or semantic errors encountered during parsing.

ASTERISK_AFTER_PTR_DEREF = 0
CHAINED_COMPARISON_OPERATORS = 1
COMPTIME_DOC_COMMENT = 39
C_STYLE_CONTAINER = 54
DECL_BETWEEN_FIELDS = 2
EXPECTED_BLOCK = 3
EXPECTED_BLOCK_OR_ASSIGNMENT = 4
EXPECTED_BLOCK_OR_EXPR = 5
EXPECTED_BLOCK_OR_FIELD = 6
EXPECTED_COMMA_AFTER_ARG = 45
EXPECTED_COMMA_AFTER_CAPTURE = 50
EXPECTED_COMMA_AFTER_FIELD = 44
EXPECTED_COMMA_AFTER_FOR_OPERAND = 49
EXPECTED_COMMA_AFTER_INITIALIZER = 47
EXPECTED_COMMA_AFTER_PARAM = 46
EXPECTED_COMMA_AFTER_SWITCH_PRONG = 48
EXPECTED_CONTAINER = 27
EXPECTED_CONTAINER_MEMBERS = 7
EXPECTED_CONTINUE_EXPR = 41
EXPECTED_EXPR = 8
EXPECTED_EXPR_OR_ASSIGNMENT = 9
EXPECTED_EXPR_OR_VAR_DECL = 10
EXPECTED_FN = 11
EXPECTED_INITIALIZER = 51
EXPECTED_INLINABLE = 12
EXPECTED_LABELABLE = 13
EXPECTED_LOOP_PAYLOAD = 26
EXPECTED_PARAM_LIST = 14
EXPECTED_PREFIX_EXPR = 15
EXPECTED_PRIMARY_TYPE_EXPR = 16
EXPECTED_PUB_ITEM = 17
EXPECTED_RETURN_TYPE = 18
EXPECTED_SEMI_AFTER_DECL = 42
EXPECTED_SEMI_AFTER_STMT = 43
EXPECTED_SEMI_OR_ELSE = 19
EXPECTED_SEMI_OR_LBRACE = 20
EXPECTED_STATEMENT = 21
EXPECTED_SUFFIX_OP = 22
EXPECTED_TOKEN = 63
EXPECTED_TYPE_EXPR = 23
EXPECTED_VAR_CONST = 55
EXPECTED_VAR_DECL = 24
EXPECTED_VAR_DECL_OR_FN = 25
EXTERN_FN_BODY = 28
EXTRA_ADDRSPACE_QUALIFIER = 29
EXTRA_ALIGN_QUALIFIER = 30
EXTRA_ALLOWZERO_QUALIFIER = 31
EXTRA_CONST_QUALIFIER = 32
EXTRA_FOR_CAPTURE = 58
EXTRA_VOLATILE_QUALIFIER = 33
FOR_INPUT_NOT_CAPTURED = 59
INVALID_AMPERSAND_AMPERSAND = 53
INVALID_BIT_RANGE = 35
INVALID_BYTE = 64
MISMATCHED_BINARY_OP_WHITESPACE = 52
NEXT_FIELD = 62
PREVIOUS_FIELD = 61
PTR_MOD_ON_ARRAY_CHILD_TYPE = 34
SAME_LINE_DOC_COMMENT = 36
TEST_DOC_COMMENT = 38
UNATTACHED_DOC_COMMENT = 37
VARARGS_NONFINAL = 40
VAR_CONST_DECL = 57
WRONG_EQUAL_VAR_DECL = 56
ZIG_STYLE_CONTAINER = 60
class zyntex.parsing.bindings.GenericSlice[source]

A generic container for FFI slices, representing a pointer and it’s length.

property is_empty: bool

Whether the slice is empty.

len

Structure/Union member

ptr

Structure/Union member

to_list(ctype, encoding='utf-8')[source]

Return the slice as a Python list.

If ctype is PyString, the entire underlying byte array is decoded into a single Python string and returned as a list with one element. For other ctypes, the slice is returned as a list of individual instances.

May raise a EOFError if the slice is empty.

Return type:

List

class zyntex.parsing.bindings.NodeParam[source]

Represents a node parameter.

is_comptime

Structure/Union member

name

Structure/Union member

type

Structure/Union member

class zyntex.parsing.bindings.NodeTag(*values)[source]

Bindings to the Zig std.zig.Ast.Node.Tag enum. Ref: https://github.com/ziglang/zig/blob/0.15.1/lib/std/zig/Ast.zig#L3089

These enum values correspond to the numeric values returned by Zig parsing API.

ADD = 43
ADDRESS_OF = 63
ADD_SAT = 48
ADD_WRAP = 46
ALIGNED_VAR_DECL = 5
ANYFRAME_LITERAL = 123
ANYFRAME_TYPE = 122
ARRAY_ACCESS = 76
ARRAY_CAT = 45
ARRAY_INIT = 83
ARRAY_INIT_COMMA = 84
ARRAY_INIT_DOT = 81
ARRAY_INIT_DOT_COMMA = 82
ARRAY_INIT_DOT_TWO = 79
ARRAY_INIT_DOT_TWO_COMMA = 80
ARRAY_INIT_ONE = 77
ARRAY_INIT_ONE_COMMA = 78
ARRAY_MULT = 40
ARRAY_TYPE = 66
ARRAY_TYPE_SENTINEL = 67
ASM = 160
ASM_INPUT = 162
ASM_LEGACY = 159
ASM_OUTPUT = 161
ASM_SIMPLE = 158
ASSIGN = 34
ASSIGN_ADD = 20
ASSIGN_ADD_SAT = 32
ASSIGN_ADD_WRAP = 29
ASSIGN_BIT_AND = 25
ASSIGN_BIT_OR = 27
ASSIGN_BIT_XOR = 26
ASSIGN_DESTRUCTURE = 35
ASSIGN_DIV = 18
ASSIGN_MOD = 19
ASSIGN_MUL = 17
ASSIGN_MUL_SAT = 31
ASSIGN_MUL_WRAP = 28
ASSIGN_SHL = 22
ASSIGN_SHL_SAT = 23
ASSIGN_SHR = 24
ASSIGN_SUB = 21
ASSIGN_SUB_SAT = 33
ASSIGN_SUB_WRAP = 30
BANG_EQUAL = 12
BIT_AND = 53
BIT_NOT = 61
BIT_OR = 55
BIT_XOR = 54
BLOCK = 156
BLOCK_SEMICOLON = 157
BLOCK_TWO = 154
BLOCK_TWO_SEMICOLON = 155
BOOL_AND = 57
BOOL_NOT = 59
BOOL_OR = 58
BREAK = 115
BUILTIN_CALL = 134
BUILTIN_CALL_COMMA = 135
BUILTIN_CALL_TWO = 132
BUILTIN_CALL_TWO_COMMA = 133
CALL = 95
CALL_COMMA = 96
CALL_ONE = 93
CALL_ONE_COMMA = 94
CATCH = 8
CHAR_LITERAL = 124
COMPTIME = 152
CONTAINER_DECL = 137
CONTAINER_DECL_ARG = 141
CONTAINER_DECL_ARG_TRAILING = 142
CONTAINER_DECL_TRAILING = 138
CONTAINER_DECL_TWO = 139
CONTAINER_DECL_TWO_TRAILING = 140
CONTAINER_FIELD = 151
CONTAINER_FIELD_ALIGN = 150
CONTAINER_FIELD_INIT = 149
CONTINUE = 114
DEFER = 7
DEREF = 75
DIV = 38
ENUM_LITERAL = 128
EQUAL_EQUAL = 11
ERRDEFER = 6
ERROR_SET_DECL = 136
ERROR_UNION = 164
ERROR_VALUE = 163
FIELD_ACCESS = 9
FN_DECL = 121
FN_PROTO = 120
FN_PROTO_MULTI = 118
FN_PROTO_ONE = 119
FN_PROTO_SIMPLE = 117
FOR = 108
FOR_RANGE = 109
FOR_SIMPLE = 107
GLOBAL_VAR_DECL = 2
GREATER_OR_EQUAL = 16
GREATER_THAN = 14
GROUPED_EXPRESSION = 131
IDENTIFIER = 127
IF = 111
IF_SIMPLE = 110
LESS_OR_EQUAL = 15
LESS_THAN = 13
LOCAL_VAR_DECL = 3
MERGE_ERROR_SETS = 36
MOD = 39
MUL = 37
MULTILINE_STRING_LITERAL = 130
MUL_SAT = 42
MUL_WRAP = 41
NEGATION = 60
NEGATION_WRAP = 62
NOSUSPEND = 153
NUMBER_LITERAL = 125
OPTIONAL_TYPE = 65
OR_ELSE = 56
PTR_TYPE = 70
PTR_TYPE_ALIGNED = 68
PTR_TYPE_BIT_RANGE = 71
PTR_TYPE_SENTINEL = 69
RESUME = 113
RETURN = 116
ROOT = 0
SHL = 50
SHL_SAT = 51
SHR = 52
SIMPLE_VAR_DECL = 4
SLICE = 73
SLICE_OPEN = 72
SLICE_SENTINEL = 74
STRING_LITERAL = 129
STRUCT_INIT = 91
STRUCT_INIT_COMMA = 92
STRUCT_INIT_DOT = 89
STRUCT_INIT_DOT_COMMA = 90
STRUCT_INIT_DOT_TWO = 87
STRUCT_INIT_DOT_TWO_COMMA = 88
STRUCT_INIT_ONE = 85
STRUCT_INIT_ONE_COMMA = 86
SUB = 44
SUB_SAT = 49
SUB_WRAP = 47
SUSPEND = 112
SWITCH = 97
SWITCH_CASE = 101
SWITCH_CASE_INLINE = 102
SWITCH_CASE_INLINE_ONE = 100
SWITCH_CASE_ONE = 99
SWITCH_COMMA = 98
SWITCH_RANGE = 103
TAGGED_UNION = 143
TAGGED_UNION_ENUM_TAG = 147
TAGGED_UNION_ENUM_TAG_TRAILING = 148
TAGGED_UNION_TRAILING = 144
TAGGED_UNION_TWO = 145
TAGGED_UNION_TWO_TRAILING = 146
TEST_DECL = 1
TRY = 64
UNREACHABLE_LITERAL = 126
UNWRAP_OPTIONAL = 10
WHILE = 106
WHILE_CONT = 105
WHILE_SIMPLE = 104
class zyntex.parsing.bindings.PrimitiveType(*values)[source]

Bindings for Zig primitive types. Ref: https://ziglang.org/documentation/0.15.1/#Primitive-Types

anyerror = 'anyerror'
anyopaque = 'anyopaque'
bool = 'bool'
c_char = 'c_char'
c_int = 'c_int'
c_long = 'c_long'
c_longdouble = 'c_longdouble'
c_longlong = 'c_longlong'
c_short = 'c_short'
c_uint = 'c_uint'
c_ulong = 'c_ulong'
c_ulonglong = 'c_ulonglong'
c_ushort = 'c_ushort'
comptime_float = 'comptime_float'
comptime_int = 'comptime_int'
f128 = 'f128'
f16 = 'f16'
f32 = 'f32'
f64 = 'f64'
f80 = 'f80'
i128 = 'i128'
i16 = 'i16'
i32 = 'i32'
i64 = 'i64'
i8 = 'i8'
isize = 'isize'
noreturn = 'noreturn'
type = 'type'
u128 = 'u128'
u16 = 'u16'
u32 = 'u32'
u64 = 'u64'
u8 = 'u8'
usize = 'usize'
void = 'void'
class zyntex.parsing.bindings.PyASTNode(parent, node)[source]

Represents a high-level Python wrapper for a single ASTNode. Provides convenient accessors for commonly used node information.

property align: str | None

The align value for the node.

property body: str | None

Node’s raw body.

is_const()[source]

Whether the node is marked as const.

Return type:

bool

is_container()[source]

True if the node is a container (Enum, Struct, Union, or Opaque).

Return type:

bool

is_enum()[source]

Whether the node points to an enum.

Return type:

bool

is_error_union()[source]

Whether the node is a part of an error union.

Return type:

bool

is_export()[source]

True if the node is marked as export.

Return type:

bool

is_extern()[source]

True if the node is marked as extern.

Return type:

bool

is_opaque()[source]

Whether the node points to an opaque.

Return type:

bool

is_public()[source]

True if the node is marked as pub.

Return type:

bool

is_struct()[source]

Whether the node points to a struct.

Return type:

bool

is_union()[source]

Whether the node points to a union.

Return type:

bool

property params: List[NodeParam]

A list of node’s parameters. For functions, these are arguments

property parent: PyTranslationUnit

The parent of this ASTNode.

property released: bool

Indicates whether the ASTNode has been released.

property source: str

Raw source of the node.

property spelling: str

The node’s spelling as a decoded UTF-8 string.

property tag: NodeTag

The node’s tag.

property type: PyASTNode | None

The type node assigned to Node. For functions, it’s the return type. For variable declarations, it specifies the type hint.

class zyntex.parsing.bindings.PyString[source]

A special type for GenericSlice to treat an entire array of bytes as a single py string.

class zyntex.parsing.bindings.PyTranslationUnit(lib, tu_ptr, path=None)[source]

Represents a parsed translation unit for a single source file.

Manages parsing, memory management, and provides convenient access to the underlying translation unit’s resources at a higher level.

errors()[source]

A list of ErrorReport instances for all errors encountered during parsing. Parsing continues despite errors, so this list may contain multiple reports.

Return type:

list[ErrorReport]

errors_count()[source]

Retrieves the count of errors parsed in the translation unit.

Return type:

int

classmethod from_path(lib, path)[source]
Return type:

PyTranslationUnit

classmethod from_source(lib, source)[source]
Return type:

PyTranslationUnit

property lib: CDLL

Gets the low-level ctypes.CDLL handle for the native parser library.

nodes()[source]

A list of AST nodes parsed in the translation unit.

Return type:

list[PyASTNode]

nodes_count()[source]

Gets the total number of AST nodes within this translation unit.

Return type:

int

property path: str

The original file path used for parsing.

property ptr: Any

Gets the low-level pointer to the translation unit.

release()[source]

Manually release TranslationUnit memory. Once completed, unit resources will be no longer available.

Return type:

None

property released: bool

Whether the translation unit has been released.

root_nodes()[source]

The root AST nodes parsed in the translation unit.

Return type:

list[PyASTNode]

property source: str

Fetches the full source code as a decoded UTF-8 string.

tokens()[source]

A list of AST tokens parsed in the translation unit.

Return type:

list[ASTToken]

tokens_count()[source]

Retrieves the count of tokens parsed in the translation unit.

Return type:

int

class zyntex.parsing.bindings.TokenTag(*values)[source]

Bindings to the Zig std.zig.tokenizer.Token.Tag enum. Ref: https://github.com/ziglang/zig/blob/0.15.1/lib/std/zig/tokenizer.zig#L65

AMPERSAND = 56
AMPERSAND_EQUAL = 57
ANGLE_BRACKET_ANGLE_BRACKET_LEFT = 61
ANGLE_BRACKET_ANGLE_BRACKET_LEFT_EQUAL = 62
ANGLE_BRACKET_ANGLE_BRACKET_LEFT_PIPE = 63
ANGLE_BRACKET_ANGLE_BRACKET_LEFT_PIPE_EQUAL = 64
ANGLE_BRACKET_ANGLE_BRACKET_RIGHT = 67
ANGLE_BRACKET_ANGLE_BRACKET_RIGHT_EQUAL = 68
ANGLE_BRACKET_LEFT = 59
ANGLE_BRACKET_LEFT_EQUAL = 60
ANGLE_BRACKET_RIGHT = 65
ANGLE_BRACKET_RIGHT_EQUAL = 66
ARROW = 51
ASTERISK = 44
ASTERISK_ASTERISK = 46
ASTERISK_EQUAL = 45
ASTERISK_PERCENT = 47
ASTERISK_PERCENT_EQUAL = 48
ASTERISK_PIPE = 49
ASTERISK_PIPE_EQUAL = 50
BANG = 8
BANG_EQUAL = 15
BUILTIN = 7
CARET = 29
CARET_EQUAL = 30
CHAR_LITERAL = 5
COLON = 52
COMMA = 55
CONTAINER_DOC_COMMENT = 72
DOC_COMMENT = 71
ELLIPSIS2 = 27
ELLIPSIS3 = 28
EOF = 6
EQUAL = 12
EQUAL_ANGLE_BRACKET_RIGHT = 14
EQUAL_EQUAL = 13
IDENTIFIER = 2
INVALID = 0
INVALID_PERIODASTERISKS = 1
KEYWORD_ADDRSPACE = 73
KEYWORD_ALIGN = 74
KEYWORD_ALLOWZERO = 75
KEYWORD_AND = 76
KEYWORD_ANYFRAME = 77
KEYWORD_ANYTYPE = 78
KEYWORD_ASM = 79
KEYWORD_BREAK = 80
KEYWORD_CALLCONV = 81
KEYWORD_CATCH = 82
KEYWORD_COMPTIME = 83
KEYWORD_CONST = 84
KEYWORD_CONTINUE = 85
KEYWORD_DEFER = 86
KEYWORD_ELSE = 87
KEYWORD_ENUM = 88
KEYWORD_ERRDEFER = 89
KEYWORD_ERROR = 90
KEYWORD_EXPORT = 91
KEYWORD_EXTERN = 92
KEYWORD_FN = 93
KEYWORD_FOR = 94
KEYWORD_IF = 95
KEYWORD_INLINE = 96
KEYWORD_NOALIAS = 97
KEYWORD_NOINLINE = 98
KEYWORD_NOSUSPEND = 99
KEYWORD_OPAQUE = 100
KEYWORD_OR = 101
KEYWORD_ORELSE = 102
KEYWORD_PACKED = 103
KEYWORD_PUB = 104
KEYWORD_RESUME = 105
KEYWORD_RETURN = 106
KEYWORD_STRUCT = 108
KEYWORD_SUSPEND = 109
KEYWORD_SWITCH = 110
KEYWORD_TEST = 111
KEYWORD_THREADLOCAL = 112
KEYWORD_TRY = 113
KEYWORD_UNION = 114
KEYWORD_UNREACHABLE = 115
KEYWORD_VAR = 116
KEYWORD_VOLATILE = 117
KEYWORD_WHILE = 118
L_BRACE = 21
L_BRACKET = 23
L_PAREN = 16
MINUS = 38
MINUS_EQUAL = 39
MINUS_PERCENT = 40
MINUS_PERCENT_EQUAL = 41
MINUS_PIPE = 42
MINUS_PIPE_EQUAL = 43
MULTILINE_STRING_LITERAL_LINE = 4
NUMBER_LITERAL = 70
PERCENT = 19
PERCENT_EQUAL = 20
PERIOD = 25
PERIOD_ASTERISK = 26
PIPE = 9
PIPE_EQUAL = 11
PIPE_PIPE = 10
PLUS = 31
PLUS_EQUAL = 33
PLUS_PERCENT = 34
PLUS_PERCENT_EQUAL = 35
PLUS_PIPE = 36
PLUS_PIPE_EQUAL = 37
PLUS_PLUS = 32
QUESTION_MARK = 58
R_BRACE = 22
R_BRACKET = 24
R_PAREN = 17
SEMICOLON = 18
SLASH = 53
SLASH_EQUAL = 54
STRING_LITERAL = 3
TILDE = 69
class zyntex.parsing.bindings.TranslationUnit[source]

Represents a parsed translation unit from the Zig AST.

zyntex.parsing.bindings.get_native_library(lib_dir=None)[source]
Return type:

CDLL

zyntex.parsing.bindings.init_native_library(lib_dir=None)[source]
Return type:

None