ml_switcheroo.core.tikz.parser¶
TikZ Parser (Lexer & Logical Reconstruction).
This module provides the TikzParser which consumes raw LaTeX/TikZ source code and reconstructs the LogicalGraph representation. It effectively reverses the operation of the TikzEmitter.
Capabilities:
Tokenization: Regex-based lexer for LaTeX commands, groups, and options.
Structural Parsing: Identifies nodes, edges, and environments via recursive descent.
Metadata Extraction: Parses HTML-like tabular environments embedded in node labels to recover layer hyperparameters (e.g., kernel size, stride).
Graph Reconstruction: Builds a LogicalGraph object compatible with the rest of the transpiler pipeline.
Classes¶
Enumeration of LaTeX/TikZ token types. |
|
A lexical unit with position info. |
|
Regex-based tokenizer for TikZ source code. |
|
Parses tokenized TikZ code into a LogicalGraph. |
Module Contents¶
- class ml_switcheroo.core.tikz.parser.TokenKind(*args, **kwds)[source]¶
Bases:
enum.EnumEnumeration of LaTeX/TikZ token types.
- COMMAND¶
- LBRACE¶
- RBRACE¶
- LBRACKET¶
- RBRACKET¶
- LPAREN¶
- RPAREN¶
- SEMICOLON¶
- ARROW¶
- WORD¶
- NUMBER¶
- COMMENT¶
- WHITESPACE¶
- EOF¶
- class ml_switcheroo.core.tikz.parser.Token[source]¶
A lexical unit with position info.
- text: str¶
- line: int¶
- col: int¶
- class ml_switcheroo.core.tikz.parser.TikzLexer(text: str)[source]¶
Regex-based tokenizer for TikZ source code.
Splits raw LaTeX strings into a stream of typed Tokens, handling symbols, commands, strings, and whitespace.
- PATTERNS¶
- text¶
- pos = 0¶
- line = 1¶
- col = 1¶
- class ml_switcheroo.core.tikz.parser.TikzParser(text: str)[source]¶
Parses tokenized TikZ code into a LogicalGraph.
This parser implements a recursive descent strategy tailored to the specific TikZ subset produced by the TikzEmitter. It is not a general-purpose TeX parser.
- lexer¶
- tokens = []¶
- pos = 0¶
- graph¶