Skip to main content

lift_ast/
lib.rs

1//! LIFT AST: Lexer, parser, and AST for the `.lif` source language.
2//!
3//! This crate provides tokenisation, parsing, and IR construction from
4//! LIFT source files. Use [`Lexer`] to tokenise, [`Parser`] to parse,
5//! and [`IrBuilder`] to lower the AST into the core IR.
6
7pub mod ast;
8pub mod builder;
9pub mod lexer;
10pub mod parser;
11pub mod token;
12
13pub use ast::*;
14pub use builder::IrBuilder;
15pub use lexer::Lexer;
16pub use parser::Parser;
17pub use token::{Token, TokenKind};
18
19/// Convenience: parse a `.lif` source string into a Program AST.
20pub fn parse_source(source: &str) -> Result<Program, Vec<parser::ParseError>> {
21    let mut lexer = Lexer::new(source);
22    let tokens = lexer.tokenize().to_vec();
23    Parser::new(tokens).parse()
24}
25
26/// Convenience: lower a Program AST into a populated Context.
27pub fn build_context(program: &Program) -> Result<lift_core::Context, String> {
28    let mut ctx = lift_core::Context::new();
29    let mut builder = IrBuilder::new();
30    builder.build_program(&mut ctx, program)?;
31    Ok(ctx)
32}