Skip to main content

Crate sage_parser

Crate sage_parser 

Source
Expand description

Lexer and parser for the Sage language.

This crate provides tokenization and parsing for Sage source code, transforming source text into a typed Abstract Syntax Tree (AST).

§Example

use sage_parser::{lex, parse};
use std::sync::Arc;

let source = r#"
    agent Main {
        on start {
            emit(42);
        }
    }
    run Main;
"#;

let lex_result = lex(source).expect("lexing failed");
let source_arc: Arc<str> = Arc::from(source);
let (program, errors) = parse(lex_result.tokens(), source_arc);

assert!(errors.is_empty());
assert!(program.is_some());

Re-exports§

pub use span::Ident;
pub use span::Span;
pub use ast::*;

Modules§

ast
Abstract Syntax Tree definitions for the Sage language.
span
Source span types for error reporting.

Structs§

LexError
Error type for lexer failures.
LexErrorLocation
A single lexer error at a specific location.
LexResult
Result of lexing source code.
Spanned
A token with its source span.

Enums§

Token
All tokens in the Sage language.
TypeExpr
A type expression as it appears in source code.

Traits§

Logos
Trait implemented for an enum representing all tokens. You should never have to implement it manually, use the #[derive(Logos)] attribute on your enum.

Functions§

lex
Lex source code into tokens.
lex_partial
Lex source code, returning tokens even if there are errors.
parse
Parse a sequence of tokens into a Program AST.

Type Aliases§

ParseError
Parse error type using byte range spans.

Derive Macros§

Logos