ecaxpr/
lib.rs

1mod preproc;
2mod ast;
3mod table;
4mod states;
5
6use anyhow::{Result, Context, anyhow};
7use crate::ast::Parseable;
8
9fn read_source(path: &str) -> Result<String> {
10    std::fs::read_to_string(path)
11    .with_context(||
12        format!("Failed to read file at path '{}'", path)
13    )
14}
15
16pub fn run(path: &str) -> Result<()> {
17    let source: String = read_source(path)?;
18    
19    let mut flat_parser = preproc::tokenize(source);
20
21    let parsers = crate::preproc::Parsers::new(&mut flat_parser).ok_or(
22        anyhow!("Could not determine different parts of the script.")
23    )?;
24
25    let mut expr_parser = parsers.expr_parser;
26
27    let expr = ast::Expr::consume(&mut expr_parser)?;
28
29    let table = ast::build_table(expr);
30
31    let mut states_parser = parsers.states_parser;
32
33    let mut states = states::States::parse(&mut states_parser);
34
35    let steps = parsers.steps;
36
37    for _ in 0..steps {
38        states.print();
39        states.update_using(&table);
40    }
41
42    Ok(())
43}