zyntex.code_generation

class zyntex.code_generation.IPrinter(dispatcher)[source]

Base interface for all printers.

Each printer receives a dispatcher in its constructor and must implement print(target) to produce the output for a node.

abstractmethod print(target)[source]

Produced output of the printer.

Return type:

str

class zyntex.code_generation.PrinterConfiguration(line_ending='\\n\\n')[source]

Printer formatting options.

Attributes:

line_ending: String used to join/terminate printed elements (e.g. “

“).

line_ending: str = '\n\n'
class zyntex.code_generation.PrinterDispatcher(configuration=None)[source]

Collects printers and chooses the right one for each node.

You can register printers with add, remove them with remove, and use print to get code for any supported node.

add(target_type, target_printer_type)[source]

Register a printer for the given node type.

Return type:

None

print(target)[source]

Produces source code for the given AST node.

Return type:

str

remove(target_type)[source]

Unregister the printer for the given node type.

Return type:

None

class zyntex.code_generation.premade.DefaultCodePrinter[source]

Printer that combines all default printers into one.

print(target)[source]

Produced output of the printer.

Return type:

str

class zyntex.code_generation.premade.FunctionPrinter(dispatcher)[source]

Printer for Zig function declarations.

print(target)[source]

Produced output of the printer.

Return type:

str

static target_type()[source]

The NodeElement this printer handles.

Return type:

type[FunctionDeclaration]

class zyntex.code_generation.premade.IDefaultPrintable(dispatcher)[source]

Base for printers that register themselves automatically.

Subclasses must define target_type() and will be added to the shared dispatcher.

default_dispatcher = <zyntex.code_generation.printer.PrinterDispatcher object>
abstractmethod static target_type()[source]

The NodeElement this printer handles.

Return type:

type

class zyntex.code_generation.premade.SourceCodePrinter(dispatcher)[source]

Printer for Zig source code.

print(target)[source]

Produced output of the printer.

Return type:

str

static target_type()[source]

The NodeElement this printer handles.

Return type:

type[SourceCode]

class zyntex.code_generation.premade.SourceFilePrinter(dispatcher)[source]

Printer for Zig source file.

print(target)[source]

Produced output of the printer.

Return type:

str

static target_type()[source]

The NodeElement this printer handles.

Return type:

type[SourceFile]

class zyntex.code_generation.premade.TestPrinter(dispatcher)[source]

Printer for Zig test declarations.

print(target)[source]

Produced output of the printer.

Return type:

str

static target_type()[source]

The NodeElement this printer handles.

Return type:

type[TestDeclaration]

class zyntex.code_generation.premade.TypePrinter(dispatcher)[source]

Printer for Zig type nodes.

print(target)[source]

Produced output of the printer.

Return type:

str

static target_type()[source]

The NodeElement this printer handles.

Return type:

type[TypeNode]

class zyntex.code_generation.premade.VariablePrinter(dispatcher)[source]

Printer for Zig variable declarations.

print(target)[source]

Produced output of the printer.

Return type:

str

static target_type()[source]

The NodeElement this printer handles.

Return type:

type[VariableDeclaration]