ast: formatting; main: explicit verbosity

This commit is contained in:
2025-10-17 06:57:21 -04:00
parent f05d480b35
commit db9c75b3c6
3 changed files with 11 additions and 6 deletions

View File

@@ -438,7 +438,7 @@ impl<A: Annotation> Display for Expr<A> {
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<A: Annotation> Display for Expr<A> {
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 => "{}",

View File

@@ -205,7 +205,10 @@ fn subst() -> Result<(), Box<dyn Error>> {
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::<Expr>(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);
}
_ => {}

View File

@@ -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