bulloak_syntax/
lib.rs

1//! The syntax parser module.
2//!
3//! This module includes everything necessary to convert from a tree
4//! in string form to an AST. It also includes a semantic analyzer.
5
6mod ast;
7mod char;
8mod error;
9pub mod parser;
10pub mod semantics;
11mod span;
12mod splitter;
13mod test_utils;
14pub mod tokenizer;
15pub mod utils;
16mod visitor;
17
18pub use ast::{Action, Ast, Condition, Description, Root};
19pub use error::FrontendError;
20pub use span::{Position, Span};
21pub use tokenizer::{Token, TokenKind};
22pub use visitor::Visitor;
23
24/// Parses a string containing trees into ASTs.
25pub fn parse(text: &str) -> anyhow::Result<Vec<ast::Ast>> {
26    splitter::split_trees(text).map(parse_one).collect()
27}
28
29/// Parses a string containing a single tree into an AST.
30pub fn parse_one(text: &str) -> anyhow::Result<ast::Ast> {
31    let tokens = tokenizer::Tokenizer::new().tokenize(text)?;
32    let ast = parser::Parser::new().parse(text, &tokens)?;
33    let mut analyzer = semantics::SemanticAnalyzer::new(text);
34    analyzer.analyze(&ast)?;
35
36    Ok(ast)
37}