Slang Source Backend

Slang source backend exports for CrossGL Translator.

Slang AST Node definitions

class crosstl.backend.slang.SlangAst.ExportNode(exported_items)[source]

Bases: ASTNode

Node representing an export statement

class crosstl.backend.slang.SlangAst.ExtensionNode(extended_type, methods)[source]

Bases: ASTNode

Node representing a Slang extension

class crosstl.backend.slang.SlangAst.GenericNode(name, constraints=None)[source]

Bases: ASTNode

Node representing a generic type parameter

class crosstl.backend.slang.SlangAst.ImportNode(module_path, imported_items=None, alias=None)[source]

Bases: ASTNode

Node representing an import statement

class crosstl.backend.slang.SlangAst.TypedefNode(name, target_type)[source]

Bases: ASTNode

Node representing a type alias

Lexer for importing Slang source into CrossGL Translator.

class crosstl.backend.slang.SlangLexer.SlangLexer(code)[source]

Bases: object

Tokenize Slang source for the Slang backend parser.

classmethod from_file(filepath, chunk_size=8192)[source]

Create a lexer instance from a Slang source file.

Return type:

SlangLexer

token_generator()[source]

Yield Slang tokens while skipping whitespace and comments.

Return type:

Iterator[Tuple[str, str]]

tokenize()[source]

Return the full token stream as (token_type, text) tuples.

Return type:

List[Tuple[str, str]]

Parser for Slang source AST construction.

class crosstl.backend.slang.SlangParser.SlangParser(tokens)[source]

Bases: object

Parse Slang tokens into the Slang backend AST.

eat(token_type)[source]

Consume the current token when it matches token_type.

parse()[source]

Parse the complete Slang token stream into a shader AST.

parse_shader()[source]

Parse top-level Slang declarations, functions, and cbuffers.

skip_comments()[source]

Advance past comment tokens before parsing syntax.

Reverse code generator that emits CrossGL from Slang AST nodes.

class crosstl.backend.slang.SlangCrossGLCodeGen.SlangToCrossGLConverter[source]

Bases: object

Serialize Slang backend AST nodes back into CrossGL source.

generate(ast)[source]

Generate complete CrossGL source from a parsed Slang AST.

generate_expression(expr, is_main=False)[source]

Render a Slang backend expression node as CrossGL syntax.

generate_function(func, indent=1)[source]

Render one Slang function node as a CrossGL function.

map_semantic(semantic)[source]

Map a Slang semantic to CrossGL semantic annotation syntax.

map_type(slang_type)[source]

Map a Slang type name to the closest CrossGL type name.