jsslint_core/tex/
debug.rs1use super::node::{GroupDelims, MathKind, Node};
16use super::prose;
17
18fn kind_label(node: &Node) -> String {
19 match node {
20 Node::Chars(_) => "Chars".to_string(),
21 Node::Comment(_) => "Comment".to_string(),
22 Node::Macro(m) => format!("Macro:{}", m.macroname),
23 Node::Group(g) => match g.delims {
24 GroupDelims::Brace => "Group:{".to_string(),
25 GroupDelims::Bracket => "Group:[".to_string(),
26 },
27 Node::Environment(e) => format!("Environment:{}", e.environmentname),
28 Node::Math(m) => match m.kind {
29 MathKind::Inline => "Math:inline".to_string(),
30 MathKind::Display => "Math:display".to_string(),
31 },
32 Node::Specials(s) => format!("Specials:{}", s.chars),
33 }
34}
35
36pub fn dump(nodes: &[Node]) -> String {
38 let mut out = String::new();
39 prose::walk(nodes, &mut |node, ancestors| {
40 let depth = ancestors.len();
41 let span = node.span();
42 let prose = prose::is_in_prose_context(ancestors);
43 out.push_str(&format!(
44 "{depth}\t{pos}\t{end}\t{kind}\t{prose}\n",
45 pos = span.pos,
46 end = span.end(),
47 kind = kind_label(node),
48 prose = prose,
49 ));
50 });
51 out
52}