mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2024-11-24 14:28:44 +01:00
handle debug pretty printing
This commit is contained in:
parent
883b0c804e
commit
958857cb58
|
@ -31,34 +31,40 @@ fn debug_print_output<SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError>(
|
||||||
lvl: i32,
|
lvl: i32,
|
||||||
errs: &mut Vec<&SyntaxErr>,
|
errs: &mut Vec<&SyntaxErr>,
|
||||||
) -> std::fmt::Result {
|
) -> std::fmt::Result {
|
||||||
for _ in 0..lvl {
|
if f.alternate() {
|
||||||
f.write_str(" ")?;
|
for _ in 0..lvl {
|
||||||
|
f.write_str(" ")?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
let maybe_newline = if f.alternate() { "\n" } else { " " };
|
||||||
|
|
||||||
match node {
|
match node {
|
||||||
NodeOrToken::Node(n) => {
|
NodeOrToken::Node(n) => {
|
||||||
let kind: SyntaxKind = node.kind().into();
|
let kind: SyntaxKind = node.kind().into();
|
||||||
if kind != SyntaxKind::SYNTAX_ERROR {
|
if kind != SyntaxKind::SYNTAX_ERROR {
|
||||||
writeln!(f, "{:?} {{", kind)?;
|
write!(f, "{:?} {{{maybe_newline}", kind)?;
|
||||||
} else {
|
} else {
|
||||||
let err = errs
|
let err = errs
|
||||||
.pop()
|
.pop()
|
||||||
.expect("all error syntax nodes should correspond to an error");
|
.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() {
|
for c in n.children() {
|
||||||
debug_print_output::<SyntaxKind, SyntaxErr>(c, f, lvl + 1, errs)?;
|
debug_print_output::<SyntaxKind, SyntaxErr>(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) => {
|
NodeOrToken::Token(t) => {
|
||||||
writeln!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{:?} {:?};",
|
"{:?} {:?};{maybe_newline}",
|
||||||
Into::<SyntaxKind>::into(t.kind()),
|
Into::<SyntaxKind>::into(t.kind()),
|
||||||
t.text()
|
t.text()
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue