From db9c75b3c6b7003cb433ca9b2557d7b91ca48e96 Mon Sep 17 00:00:00 2001 From: John Date: Fri, 17 Oct 2025 06:57:21 -0400 Subject: [PATCH] ast: formatting; main: explicit verbosity --- src/ast.rs | 6 +++--- src/main.rs | 7 +++++-- test.sh | 4 +++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 395ec8c..35e57eb 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -438,7 +438,7 @@ impl Display for Expr { Self::Op(Op::Tuple, exprs) => f.delimit("(", ")").list(exprs, ", "), Self::Op(Op::Group, exprs) => f.list(exprs, ", "), Self::Op(Op::Meta, exprs) => match exprs.as_slice() { - [meta, expr @ ..] => f.delimit(fmt!("#[{meta}]\n"), "").list(expr, ","), + [meta, expr @ ..] => f.delimit(fmt!("#[{meta}] "), "").list(expr, ","), [] => write!(f, "#[]"), }, @@ -465,7 +465,7 @@ impl Display for Expr { impl Display for Op { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { - Op::Do => "; ", + Op::Do => ";\n", Op::As => " as ", Op::Macro => "macro ", Op::Block => "{}", @@ -550,7 +550,7 @@ impl Display for Pat { Self::Name(name) => name.fmt(f), Self::Path(path) => path.fmt(f), Self::Struct(name, bind) => match bind.as_ref() { - Pat::Op(PatOp::Tuple, parts) => f.delimit(fmt!("{name} {{"), "}").list(parts, ", "), + Pat::Op(PatOp::Tuple, parts) => f.delimit(fmt!("{name} {{ "), " }").list(parts, ", "), other => write!(f, "{name} {{ {other} }}"), }, Self::TupStruct(name, bind) => write!(f, "{name} {bind}"), diff --git a/src/main.rs b/src/main.rs index 114ac57..920a8d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -205,7 +205,10 @@ fn subst() -> Result<(), Box> { fn parse(document: &str) { let mut parser = Parser::new(Lexer::new(document)); - let isatty = std::io::stdin().is_terminal(); + let verbose = !matches!( + std::env::var("DOUGHLANG_VERBOSE").as_deref(), + Ok("false" | "0" | "no") + ); for idx in 0.. { match parser.parse::(0) { Err(e @ ParseError::EOF(s)) if s.tail == document.len() as _ => { @@ -220,7 +223,7 @@ fn parse(document: &str) { println!("\x1b[91m{e}\x1b[0m"); break; } - Ok(v) if isatty => { + Ok(v) if verbose => { println!("\x1b[{}m{v}", (idx + 5) % 6 + 31); } _ => {} diff --git a/test.sh b/test.sh index a4d6fed..d79f6cb 100755 --- a/test.sh +++ b/test.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash +export DOUGHLANG_VERBOSE="${DOUGHLANG_VERBOSE:-0}" + for file in $(find "$@" -type f); do echo $file; - cat $file | cargo run -q; + cat $file | cargo run -q $CARGO_FLAGS; done