regenerate.rs 880 B

123456789101112131415161718192021222324252627
  1. use matzo::grammar;
  2. use std::io::Write;
  3. fn main() -> Result<(), Box<dyn std::error::Error>> {
  4. for exp in std::fs::read_dir("tests")? {
  5. let exp = exp?.path().canonicalize()?;
  6. let fname = exp.file_name().ok_or("bad file name")?.to_string_lossy();
  7. if let Some(prefix) = fname.strip_suffix(".matzo") {
  8. println!("regenerating {}.matzo", prefix);
  9. let exp_filename = |new_suffix| {
  10. let mut f = exp.clone();
  11. f.pop();
  12. f.push(format!("{}.{}", prefix, new_suffix));
  13. f
  14. };
  15. let src = std::fs::read_to_string(&exp)?;
  16. if let Ok(ast) = grammar::StmtsParser::new().parse(&src) {
  17. let mut f = std::fs::File::create(exp_filename("parsed"))?;
  18. writeln!(f, "{:#?}", ast)?;
  19. }
  20. }
  21. }
  22. Ok(())
  23. }