svg-filters & basic parser #15
1 changed files with 16 additions and 3 deletions
|
@ -9,9 +9,12 @@ pub struct Output {
|
|||
pub green_node: GreenNode,
|
||||
pub errors: Vec<SyntaxError>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Output {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
debug_print_green_node(NodeOrToken::Node(&self.green_node), f, 0)
|
||||
let mut errs: Vec<&SyntaxError> = self.errors.iter().collect();
|
||||
errs.reverse();
|
||||
debug_print_green_node(NodeOrToken::Node(&self.green_node), f, 0, &mut errs)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +22,7 @@ fn debug_print_green_node(
|
|||
node: NodeOrToken<&GreenNodeData, &GreenTokenData>,
|
||||
f: &mut std::fmt::Formatter<'_>,
|
||||
lvl: i32,
|
||||
errs: &mut Vec<&SyntaxError>,
|
||||
) -> std::fmt::Result {
|
||||
for _ in 0..lvl {
|
||||
f.write_str(" ")?;
|
||||
|
@ -26,9 +30,18 @@ fn debug_print_green_node(
|
|||
|
||||
match node {
|
||||
NodeOrToken::Node(n) => {
|
||||
writeln!(f, "{:?} {{", Lang::kind_from_raw(node.kind()))?;
|
||||
let kind = Lang::kind_from_raw(node.kind());
|
||||
if kind != SyntaxKind::PARSE_ERR {
|
||||
writeln!(f, "{:?} {{", Lang::kind_from_raw(node.kind()))?;
|
||||
} else {
|
||||
let err = errs
|
||||
.pop()
|
||||
.expect("all error syntax nodes should correspond to an error");
|
||||
|
||||
writeln!(f, "{:?}: {err:?} {{", kind)?;
|
||||
}
|
||||
for c in n.children() {
|
||||
debug_print_green_node(c, f, lvl + 1)?;
|
||||
debug_print_green_node(c, f, lvl + 1, errs)?;
|
||||
}
|
||||
for _ in 0..lvl {
|
||||
f.write_str(" ")?;
|
||||
|
|
Loading…
Reference in a new issue