maya.utils.converter.parsing

AST parsing utilities for tik.maya code analysis.

This module handles parsing of Python source code using the AST module, providing utilities for analyzing tik.maya expressions without relying on tik.maya internals.

Classes

ParsedExpression

Represents a parsed tik.maya expression with context.

TikMayaASTVisitor

AST visitor that identifies tik.maya patterns in source code.

Functions

get_node_source(→ str)

Extract source code for an AST node.

parse_source(→ Tuple[ast.Module, List[str]])

Parse Python source code into AST and lines.

unparse_node(→ str)

Convert an AST node back to source code.

Module Contents

class ParsedExpression

Represents a parsed tik.maya expression with context.

col_offset: int
end_col_offset: int | None
end_line_number: int | None
line_number: int
node: ast.AST
source_segment: str
class TikMayaASTVisitor(source_lines: List[str])

Bases: ast.NodeVisitor

AST visitor that identifies tik.maya patterns in source code.

This visitor recognizes: - Node creation patterns (Transform.create(), Mesh.create(), etc.) - Attribute access patterns (node[“attr”], node.property) - Attribute assignment patterns (node[“attr”].set(), node.property = value) - Connection patterns (plug.connect(), plug >> other_plug) - Method call patterns on tik.maya objects

get_source_segment(start_line: int, start_col: int, end_line: int | None, end_col: int | None) str

Extract source code segment from line/column positions.

Args:

start_line: 1-based starting line number. start_col: 0-based starting column. end_line: 1-based ending line number (optional). end_col: 0-based ending column (optional).

Returns:

The source code segment as a string.

visit_Import(node: ast.Import) Any

Track import statements for tik modules.

visit_ImportFrom(node: ast.ImportFrom) Any

Track from … import statements for tik modules.

TIK_IMPORT_PATTERNS
TIK_TYPES
found_expressions: List[ParsedExpression] = []
source_lines
tik_imports: Dict[str, str]
tik_names: Dict[str, str]
get_node_source(node: ast.AST, source_lines: List[str]) str

Extract source code for an AST node.

Args:

node: AST node with line/column info. source_lines: List of source code lines.

Returns:

The source code corresponding to the node.

parse_source(source_code: str) Tuple[ast.Module, List[str]]

Parse Python source code into AST and lines.

Args:

source_code: Python source code string.

Returns:

Tuple of (AST module, list of source lines).

Raises:

SyntaxError: If the source code has syntax errors.

unparse_node(node: ast.AST) str

Convert an AST node back to source code.

Args:

node: AST node to unparse.

Returns:

Python source code string.