Metal Source Backend

Metal source backend exports for CrossGL Translator.

Metal AST Node definitions

Lexer for importing Metal source into CrossGL Translator.

class crosstl.backend.Metal.MetalLexer.MetalLexer(code)[source]

Bases: object

Tokenize Metal Shading Language source for the Metal parser.

classmethod from_file(filepath)[source]

Create a lexer instance from a Metal source file.

Return type:

MetalLexer

token_generator()[source]

Yield Metal 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 Metal source AST construction.

class crosstl.backend.Metal.MetalParser.MetalParser(tokens)[source]

Bases: object

Parse Metal tokens into the Metal backend shader AST.

eat(token_type)[source]

Consume the current token when it matches token_type.

parse()[source]

Parse the complete token stream into a shader node.

parse_shader()[source]

Parse top-level Metal declarations, functions, and preprocessor nodes.

peek(offset=1)[source]

Return a lookahead token without advancing the parser.

skip_comments()[source]

Advance past comment tokens before parsing syntax.

Reverse code generator that emits CrossGL from Metal AST nodes.

class crosstl.backend.Metal.MetalCrossGLCodeGen.MetalToCrossGLConverter[source]

Bases: object

Serialize Metal backend AST nodes back into CrossGL source.

generate(ast)[source]

Generate a complete CrossGL shader from a parsed Metal AST.

generate_expression(expr, is_main=False)[source]

Render a Metal backend expression node as CrossGL syntax.

generate_function(func, indent=2)[source]

Render one Metal function node as a CrossGL function block.

map_semantic(semantic)[source]

Map Metal attributes to CrossGL semantic annotation syntax.

map_type(metal_type)[source]

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