handle debug pretty printing

This commit is contained in:
Schrottkatze 2024-10-27 17:21:42 +01:00
parent 883b0c804e
commit 958857cb58
No known key found for this signature in database

View file

@ -31,34 +31,40 @@ fn debug_print_output<SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError>(
lvl: i32,
errs: &mut Vec<&SyntaxErr>,
) -> std::fmt::Result {
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::<SyntaxKind, SyntaxErr>(c, f, lvl + 1, errs)?;
}
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::<SyntaxKind>::into(t.kind()),
t.text()
)