Rust API

Parser

A builtin parser over fixed source text and options.

pub struct Parser { /* private fields */ }

impl Parser {
    pub fn new(code: String, options: ParserOptions) -> Self;

    pub fn parse(self) -> Result<AstResult, CompileError>;
}

Parser is the builtin parser used by the pipeline as the terminal fallback after every parse hook defers. It never runs the plugin chain. Use parse when plugins should be able to replace the parse result.

Parser::new

Creates a parser over code and its resolved ParserOptions.

ParserOptions

Every field is required. In a parse hook, the stage options are available as args.options.

FieldTypeDescription
cwdPathBufFilesystem root used to locate the source file; a relative input map path resolves against the source file's directory, and absolute paths are used as-is.
fileStringThe file being parsed.
languageLanguageThe grammar of the code.
source_typeSourceTypeThe module system of the code.
source_mapSourceMapOptionsThe source-map inputs and outputs requested for the step.

Parser::parse

Parses the fixed source text and returns the resulting AST. The parser resolves any requested input source map and attaches it to the returned AST; output delivery is applied by the pipeline.

AstResult is { ast: Ast }. See Ast for accessors, clone semantics, and mutation.

Example

use std::path::PathBuf;

use telarel::{
    AstResult, Language, Parser, ParserOptions, SourceMapOptions, SourceType,
};

let parser: Parser = Parser::new(
    String::from("const x: number = 1;"),
    ParserOptions {
        cwd: PathBuf::from("."),
        file: String::from("index.ts"),
        language: Language::TS,
        source_type: SourceType::Module,
        source_map: SourceMapOptions::default(),
    },
);

let result: AstResult = parser.parse()?;

Last updated on

Copyright © 2026, Alpheus

On this page