-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAST.cpp
108 lines (96 loc) · 2.26 KB
/
AST.cpp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "AST.hpp"
const QSet <QString> Environment {
Strings::Document,
Strings::Enumerate,
Strings::Itemize,
Strings::Verbatim,
"center",
};
const QSet <QString> Fragment {
Strings::BoldFace,
Strings::Hspace,
Strings::Input,
Strings::Italic,
Strings::Section,
Strings::SourceCode,
Strings::Subsection,
Strings::TextTT,
Strings::Title,
"hspace*",
"mbox",
"textsf",
Highlight::CommentBlock,
Highlight::CommentCpp,
Highlight::Escape,
Highlight::KeywordA,
Highlight::KeywordB,
Highlight::KeywordC,
Highlight::IncludeQuote,
Highlight::LineNumbering,
Highlight::NumberConstant,
Highlight::Operator,
Highlight::Preprocessor,
Highlight::Standard,
Highlight::String,
Highlight::StringSubstitution,
Highlight::Type,
};
const QSet <QString> Tag {
Strings::Backslash,
Strings::CodeTilde,
Strings::Item,
Strings::Ldots,
Strings::MakeTitle,
Strings::NormalFont,
Strings::Quote,
Strings::Textbar,
Strings::TextBackslash,
Strings::Tilde,
Strings::TTFamily,
Strings::Underscore,
"fill",
"indent",
"noindent",
"normalsize",
};
static inline constexpr uint qHash(const Node::Type &t)
{
return ::qHash(static_cast<typename std::underlying_type<std::decay_t<decltype(t)> >::type>(t));
}
Node::Type Node::typeFromName(const QString &name)
{
using TypePair = QPair <const QSet <QString> *, Node::Type>;
static const Vector <TypePair> TypeVector {
{&Environment, Type::Environment},
{&Fragment, Type::Fragment},
{&Tag, Type::Tag},
};
for (auto p : TypeVector) {
if (p.first->contains(name))
return p.second;
}
qCritical() << QString{"Unknown type for '%1'"}.arg(name);
std::exit(1);
return Type::Invalid;
}
QString Node::toString() const
{
static const QHash <Node::Type, const char *> TypeHash {
{Type::Environment, "Environment"},
{Type::Fragment, "Fragment"},
{Type::Tag, "Tag"},
{Type::Text, "Text"},
};
QString typeString = TypeHash.value(type, "Invalid");
return QString{"type = %1, value = _%2_, endParagraph = %3"}.arg(typeString).arg(value).arg(endParagraph);
}
Node & Node::appendNode(Node::Type type, const QString &value)
{
QString temp{value};
return appendNode(type, std::move(temp));
}
Node & Node::appendNode(Node::Type type, QString &&value)
{
children.push_back(Node{type, std::move(value)});
return children.back();
}