-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeanDocAst2.cpp
More file actions
91 lines (82 loc) · 2.76 KB
/
LeanDocAst2.cpp
File metadata and controls
91 lines (82 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "LeanDocAst2.h"
using namespace LeanDoc;
inline const char *Node::nodeKindName(Kind k)
{
switch (k) {
case Node::K_Document: return "Document";
case Node::K_Section: return "Section";
case Node::K_Paragraph: return "Paragraph";
case Node::K_LiteralParagraph: return "LiteralParagraph";
case Node::K_AdmonitionParagraph: return "AdmonitionParagraph";
case Node::K_DelimitedBlock: return "DelimitedBlock";
case Node::K_List: return "List";
case Node::K_ListItem: return "ListItem";
case Node::K_Table: return "Table";
case Node::K_TableRow: return "TableRow";
case Node::K_TableCell: return "TableCell";
case Node::K_BlockMacro: return "BlockMacro";
case Node::K_Directive: return "Directive";
case Node::K_ThematicBreak: return "ThematicBreak";
case Node::K_PageBreak: return "PageBreak";
case Node::K_LineComment: return "LineComment";
case Node::K_Text: return "Text";
case Node::K_Space: return "Space";
case Node::K_LineBreak: return "LineBreak";
case Node::K_Emph: return "Emph";
case Node::K_Superscript: return "Superscript";
case Node::K_Subscript: return "Subscript";
case Node::K_Link: return "Link";
case Node::K_ImageInline: return "ImageInline";
case Node::K_AnchorInline: return "AnchorInline";
case Node::K_Xref: return "Xref";
case Node::K_AttrRef: return "AttrRef";
case Node::K_InlineMacro: return "InlineMacro";
case Node::K_PassthroughInline: return "PassthroughInline";
default: return "Unknown";
}
}
static void indent(QTextStream& out, int n)
{
for (int i=0;i<n;i++)
out << " ";
}
static void dumpMeta(const BlockMeta* m, QTextStream& out)
{
if (!m) return;
if (!m->anchorId.isEmpty())
out << " anchorId=\"" << m->anchorId << "\"";
if (!m->anchorText.isEmpty())
out << " anchorText=\"" << m->anchorText << "\"";
if (!m->title.isEmpty())
out << " title=\"" << m->title << "\"";
if (!m->attrs.isEmpty())
out << " attrs=" << m->attrs.size();
}
void Node::dump(QTextStream &out, int depth)
{
indent(out, depth);
out << nodeKindName() << " @" << pos.line;
dumpMeta(meta, out);
if (!name.isEmpty())
out << " name=\"" << name << "\"";
if (!target.isEmpty())
out << " target=\"" << target << "\"";
if (!text.isEmpty())
{
QString str = text;
if( str.length() > 64 )
{
str = str.simplified().left(64);
str = "\"" + str + "\"";
str += "...";
}else
str = "\"" + str + "\"";
out << " text=" << str;
}
if (!kv.isEmpty())
out << " kv=" << kv.size();
out << "\n";
for (int i=0;i<children.size();++i) {
children[i]->dump(out, depth+1);
}
}