-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfull.rs
48 lines (39 loc) · 1.14 KB
/
full.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::fs;
use nolana::{
allocator::Allocator,
codegen::{Codegen, CodegenOptions},
parser::{Parser, ParserReturn},
semantic::SemanticChecker,
};
fn main() {
let source_text = fs::read_to_string("examples/sample.molang").unwrap();
let allocator = Allocator::default();
let ParserReturn {
program,
errors,
panicked,
} = Parser::new(&allocator, &source_text).parse();
if !errors.is_empty() {
for error in errors {
let error = error.with_source_code(source_text.clone());
print!("{error:?}");
}
if panicked {
println!("Encountered an unrecoverable error");
}
return;
}
let errors = SemanticChecker::default().check(&program);
if !errors.is_empty() {
for error in errors {
let error = error.with_source_code(source_text.clone());
print!("{error:?}");
}
return;
}
println!("AST: {:#?}", program);
let output = Codegen::default()
.with_options(CodegenOptions { minify: true })
.build(&program);
println!("Printed Molang: {output}");
}