From 958857cb58ffe1e2ca677908ee51101d022caf38 Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Sun, 27 Oct 2024 17:21:42 +0100 Subject: [PATCH] handle debug pretty printing --- crates/pawarser/src/parser/output.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/crates/pawarser/src/parser/output.rs b/crates/pawarser/src/parser/output.rs index 25b0c31..76c3cf7 100644 --- a/crates/pawarser/src/parser/output.rs +++ b/crates/pawarser/src/parser/output.rs @@ -31,34 +31,40 @@ fn debug_print_output( lvl: i32, errs: &mut Vec<&SyntaxErr>, ) -> std::fmt::Result { - for _ in 0..lvl { - f.write_str(" ")?; + if f.alternate() { + for _ in 0..lvl { + f.write_str(" ")?; + } } + let maybe_newline = if f.alternate() { "\n" } else { " " }; match node { NodeOrToken::Node(n) => { let kind: SyntaxKind = node.kind().into(); if kind != SyntaxKind::SYNTAX_ERROR { - writeln!(f, "{:?} {{", kind)?; + write!(f, "{:?} {{{maybe_newline}", kind)?; } else { let err = errs .pop() .expect("all error syntax nodes should correspond to an error"); - writeln!(f, "{:?}: {err:?} {{", kind)?; + write!(f, "{:?}: {err:?} {{{maybe_newline}", kind)?; } for c in n.children() { debug_print_output::(c, f, lvl + 1, errs)?; } - for _ in 0..lvl { - f.write_str(" ")?; + + if f.alternate() { + for _ in 0..lvl { + f.write_str(" ")?; + } } - f.write_str("}\n") + write!(f, "}}{maybe_newline}") } NodeOrToken::Token(t) => { - writeln!( + write!( f, - "{:?} {:?};", + "{:?} {:?};{maybe_newline}", Into::::into(t.kind()), t.text() )