xXenvy/zyntex
A high-level Python package to parse and generate Zig code.
Zyntex is a Python library that allows you to parse and generate Zig code at a high level. Function bodies and other low-level elements are currently returned as raw strings. Currently, it can parse Zig code written in version 0.15.1 - the supported parsing version will be continuously updated in the future.
Internally, it uses bindings to Zig's std AST parser, making it both fast and memory-efficient.
Important: currently bindings are only available for windows-x86_64
, macos-x86_64
, and linux-x86_64
.
For more information, read the docs.
Be aware that the project is at a very early stage of development and is actively being developed.
std
parser.pip install zyntex
from typing import cast
from zyntex.code_generation.premade import DefaultCodePrinter
from zyntex.parsing.syntax import VariableDeclaration
from zyntex.parsing import SourceCode
code_printer = DefaultCodePrinter()
src = SourceCode("const result: usize = 15 + 15;")
variable = cast(VariableDeclaration, src.content[0])
variable.is_public = True
print(code_printer.print(src)) # pub const result: usize = 15 + 15;