blob: df9f57d239c5d16f0ba89c4c8bd3a0a5ada52755 (
plain) (
blame)
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
|
use crate::Result;
mod lexer;
mod preprocessor;
#[cfg(test)]
mod tests;
mod tokens;
pub fn preprocess(s: &str) -> Result<String> {
let mut buf = Vec::new();
let preprocessor = preprocessor::Preprocessor::new(s, &mut buf)?;
preprocessor.preprocess()?;
let s = String::from_utf8(buf).unwrap();
Ok(s)
}
pub fn preprocess_dir(path: &std::path::Path) -> Result<()> {
for entry in std::fs::read_dir(path)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
preprocess_dir(&path)?;
} else {
if path.extension().unwrap_or_default() != "luax" {
continue;
}
let s = std::fs::read_to_string(&path)?;
let s = preprocess(&s)?;
let out_path = path.with_extension("lua");
std::fs::write(out_path, s)?;
}
}
Ok(())
}
|