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§
Modules§
- ast
- Abstract Syntax Tree definitions for the Sage language.
- span
- Source span types for error reporting.
Structs§
- LexError
- Error type for lexer failures.
- LexError
Location - A single lexer error at a specific location.
- LexResult
- Result of lexing source code.
- Spanned
- A token with its source span.
Enums§
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§
- Parse
Error - Parse error type using byte range spans.