svg-filters & basic parser #15

Merged
schrottkatze merged 67 commits from schrottkatze/iowo:svg-filters into main 2024-07-08 18:29:05 +00:00
Showing only changes of commit 29cdcfbe0c - Show all commits

View file

@ -9,9 +9,12 @@ pub struct Output {
pub green_node: GreenNode, pub green_node: GreenNode,
pub errors: Vec<SyntaxError>, pub errors: Vec<SyntaxError>,
} }
impl std::fmt::Debug for Output { impl std::fmt::Debug for Output {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 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>, node: NodeOrToken<&GreenNodeData, &GreenTokenData>,
f: &mut std::fmt::Formatter<'_>, f: &mut std::fmt::Formatter<'_>,
lvl: i32, lvl: i32,
errs: &mut Vec<&SyntaxError>,
) -> std::fmt::Result { ) -> std::fmt::Result {
for _ in 0..lvl { for _ in 0..lvl {
f.write_str(" ")?; f.write_str(" ")?;
@ -26,9 +30,18 @@ fn debug_print_green_node(
match node { match node {
NodeOrToken::Node(n) => { NodeOrToken::Node(n) => {
let kind = Lang::kind_from_raw(node.kind());
if kind != SyntaxKind::PARSE_ERR {
writeln!(f, "{:?} {{", Lang::kind_from_raw(node.kind()))?; 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() { 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 { for _ in 0..lvl {
f.write_str(" ")?; f.write_str(" ")?;