-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.rs
34 lines (27 loc) · 861 Bytes
/
build.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
use std::{
env,
error::Error,
fs::{self, File},
io::Write,
path::Path,
};
#[path = "build/lexer.rs"]
mod lexer;
#[path = "build/parser.rs"]
mod parser;
fn main() -> Result<(), Box<dyn Error>> {
let manifest_dir = env::var("CARGO_MANIFEST_DIR")?;
let manifest_dir = Path::new(&manifest_dir);
let src = ["case_folding", "numeric_types"]
.into_iter()
.map(|p| format!("unicode/{}.txt", p))
.map(|p| manifest_dir.join(p))
.map(fs::read_to_string)
.collect::<Result<String, _>>()?;
let output = parser::File::try_from(lexer::lex(&src).map_err(|e| e.to_string())?.1)?;
let output_dir = env::var("OUT_DIR")?;
let output_dir = Path::new(&output_dir);
let mut output_file = File::create(output_dir.join("unicode.rs"))?;
writeln!(output_file, "{}", output)?;
Ok(())
}