-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPPrint.h
65 lines (49 loc) · 1013 Bytes
/
PPrint.h
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
#pragma once
#include <QString>
#include <QList>
#include <type_traits>
#include "Token.h"
#include "AstNode.h"
#include "Parser.h"
template <typename T>
QString pprint(T val);
QString pprint(QList<Token> val);
QString pprint(QList<AstNode> val);
template <typename T>
QString pprintDense(QList<T> val)
{
QString out;
int lastType = -1;
for (const T &v : val)
{
if ((lastType != v.type() || v.type() != T::SYM) && lastType != -1)
out += " ";
out += QString(v);
}
return out;
}
template <typename T>
QString pprint(QList<T> val)
{
QStringList out;
for (const T &v : val)
out.append(static_cast<QString>(v));
return out.join(" ");
}
template <typename T>
QString pprint(T val)
{
return static_cast<QString>(val);
}
class PPrint
{
public:
enum Style
{
ANSI,
HTML
};
};
QString pprint(ParseResult val, const Parser &parser, PPrint::Style style = PPrint::ANSI);
void sout(QString string);
void eout(QString string);