microlang/example/no_std.rs

22 lines
594 B
Rust

#![no_std]
use alloc::string::ToString;
use microlang::eval::Context;
extern crate alloc;
pub fn main() {
// Context instantiation.
let mut context = Context::empty();
// Script to evaluate.
let lines = include_str!("./data/hello_world.mc");
// Script evaluation.
match context.eval(lines.to_string()) {
// May return errors raised during parsing or actual evaluation.
Err(err) => panic!("Failed : {err:?}"),
// Success returns the parsed AST alongside the value resulting from the evaluation.
Ok((_, value)) => assert_eq!(value.serialize(), "hello world".to_string()),
}
}