Rust API
parse
Parse source text into an AST.
pub async fn parse(
code: String,
options: ParseOptions,
plugins: Vec<SharedPluginable>,
) -> Result<AstResult, CompileError>Parses code into an AST.
The builtin parser resolves any requested input source map and is the terminal fallback after every parse hook defers.
Parameters
| Name | Type | Description |
|---|---|---|
code | String | The source text to parse. |
options | ParseOptions | The parse options. |
plugins | Vec<SharedPluginable> | The plugins to run. |
ParseOptions
Every field is optional and resolved against defaults before use.
| Field | Type | Default | Description |
|---|---|---|---|
cwd | Option<PathBuf> | process working dir | Filesystem root used to resolve relative paths. |
file | Option<String> | index.ts | The file being parsed. The language is inferred from its extension. |
language | Option<Language> | inferred | The grammar of the code. Overrides the extension inference. |
source_type | Option<SourceType> | inferred | The module system of the code. Overrides the grammar's module kind. |
input_source_map | Option<InputSourceMap> | off | The input source-map request for the step. |
parse produces an AST, so it has no output source map. The shared plugin options bag presents this request as source_map.input; a plugin-set source_map.output or top-level output is ignored by parse.
Returns
Result<AstResult, CompileError>, where AstResult is { ast: Ast }. See Ast for accessors, clone semantics, and mutation.
Example
use telarel::{parse, ParseOptions, AstResult};
let result: AstResult = parse(
String::from("const x: number = 1;"),
ParseOptions::default(),
vec![],
).await?;
assert_eq!(result.ast.source().as_ref(), "const x: number = 1;");Last updated on
Ast
An owned AST with its source text, language metadata, input source map, and mutable program access.
rewrite
Rewrite an AST with plugins.
Copyright © 2026, Alpheus