Move minimize logging to a new dump_syntax target

This commit is contained in:
Joshua Warner 2025-01-03 17:10:41 -08:00
parent c85c864b5f
commit b7ab25ee2e
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
2 changed files with 33 additions and 4 deletions

View file

@ -0,0 +1,32 @@
//! Dump a syntax tree for a given input file.
//!
//! Typical usage:
//! `cargo run --bin dump_syntax -- full file.roc`
use bumpalo::Bump;
use test_syntax::test_helpers::InputKind;
fn main() {
let args = std::env::args().collect::<Vec<String>>();
if args.len() != 3 {
eprintln!("Usage: {} [expr|full|moduledefs|header] <input>", args[0]);
std::process::exit(1);
}
let kind = match args[1].as_str() {
"expr" => InputKind::Expr,
"full" => InputKind::Full,
"moduledefs" => InputKind::ModuleDefs,
"header" => InputKind::Header,
_ => {
eprintln!("Invalid input kind: {}", args[1]);
std::process::exit(1);
}
};
let text = std::fs::read_to_string(&args[2]).unwrap();
let input = kind.with_text(&text);
let arena = Bump::new();
let output = input.parse_in(&arena);
println!("{:#?}", output);
}

View file

@ -102,10 +102,7 @@ fn round_trip_once(input: Input<'_>, options: Options) -> Option<String> {
let arena = Bump::new();
let actual = match input.parse_in(&arena) {
Ok(a) => {
println!("actual {a:#?}");
a
}
Ok(a) => a,
Err(e) => {
if options.minimize_initial_parse_error {
return Some(format!("Initial parse failed: {:?}", e.normalize(&arena)));