-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPPrint.cpp
More file actions
54 lines (43 loc) · 1.03 KB
/
PPrint.cpp
File metadata and controls
54 lines (43 loc) · 1.03 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
#include "PPrint.h"
#include <QTextStream>
void sout(QString string)
{
QTextStream(stdout) << string << '\n';
}
QString pprint(ParseResult val, const Parser &parser, PPrint::Style style)
{
if (val)
{
return "\033[32mOK\033[0m";
}
QString newline = (style == PPrint::ANSI ? "\n" : "<br>");
QString highlighted = parser.line(val.pos().line - 1) + newline;
for (int i = 1; i < val.pos().lineOffset; i++)
{
if (style == PPrint::ANSI)
highlighted += " ";
else
highlighted += " ";
}
if (style == PPrint::ANSI)
{
highlighted += "\033[31m^~~\033[0m";
}
else if (style == PPrint::HTML)
{
highlighted += "<font color=\"red\">^~~</font>";
}
return val.message() + " at " + val.pos() + newline + highlighted;
}
void eout(QString string)
{
QTextStream(stderr) << string << '\n';
}
QString pprint(QList<Token> val)
{
return pprintDense(val);
}
QString pprint(QList<AstNode> val)
{
return pprintDense(val);
}