Functions
Lexing
- lex(src: str, file_name: str) list[SpannedToken]
Separate a source file into syntactic tokens
- Parameters:
src (str) – The content of the source file to lex
file_name (str) – The name of the source file, used to annotate
Spans
- Returns:
The separated semantic tokens
- Return type:
list[SpannedToken]
Preprocessing
- preprocess(src: str, file_name: str, include_paths: Sequence[str | PathLike[str]], defines: Sequence[Define]) PreprocessorResult
Preprocess a token stream, elaborating compiler directives
- Parameters:
src (str) – The content of the source file to preprocess
file_name (str) – The name of the source file, used to annotate
Spansinclude_paths (Sequence[str | PathLike[str]]) – The include paths to search for include directives
defines (Sequence[Define]) – Any initial preprocessor definitions to operate with
- Returns:
A result indicating either a successful preprocess or the resulting error
- Return type:
- preprocess_from_lex(tokens: Sequence[SpannedToken], include_paths: Sequence[str | PathLike[str]], defines: Sequence[Define]) PreprocessorResult
Same as
preprocess(), but operates on the output oflex()Comparitively, this incurs overhead from copying data between Rust and Python’s ownership models. Only use if you need to modify the output of
lex()before preprocessing- Parameters:
- Returns:
A result indicating either a successful preprocess or the resulting error
- Return type:
Parsing
- parse(src: str, file_name: str, include_paths: Sequence[str | PathLike[str]], defines: Sequence[Define]) ParserResult
Parse the token stream into a concrete syntax tree
- Parameters:
- Returns:
A result indicating either a successful parse or the resulting error
- Return type:
- parse_from_preprocess(tokens: Sequence[SpannedToken]) ParserResult
Same as
parse(), but operates on the output ofpreprocess()Comparitively, this incurs overhead from copying data between Rust and Python’s ownership models. Only use if you need to modify the output of
preprocess()before parsing- Parameters:
tokens (Sequence[SpannedToken]) – The tokens obtained (and possibly modified) from
preprocess()(or possiblylex(), if no preprocessing is required)- Returns:
A result indicating either a successful parse or the resulting error
- Return type: