swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 1 | #pragma once |
2 | |||||
3 | #include <QString> | ||||
4 | #include <QList> | ||||
5 | |||||
swissChili | 5d3e556 | 2022-02-24 16:49:19 -0800 | [diff] [blame] | 6 | #include <type_traits> |
7 | |||||
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 8 | #include "Token.h" |
9 | #include "AstNode.h" | ||||
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame] | 10 | #include "Parser.h" |
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 11 | |
12 | template <typename T> | ||||
13 | QString pprint(T val); | ||||
14 | |||||
swissChili | d845a14 | 2022-02-25 15:46:35 -0800 | [diff] [blame] | 15 | QString pprint(QList<Token> val); |
16 | QString pprint(QList<AstNode> val); | ||||
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 17 | |
swissChili | d845a14 | 2022-02-25 15:46:35 -0800 | [diff] [blame] | 18 | template <typename T> |
19 | QString pprintDense(QList<T> val) | ||||
swissChili | 5d3e556 | 2022-02-24 16:49:19 -0800 | [diff] [blame] | 20 | { |
21 | QString out; | ||||
22 | int lastType = -1; | ||||
23 | |||||
swissChili | 5d3e556 | 2022-02-24 16:49:19 -0800 | [diff] [blame] | 24 | for (const T &v : val) |
25 | { | ||||
swissChili | d845a14 | 2022-02-25 15:46:35 -0800 | [diff] [blame] | 26 | if ((lastType != v.type() || v.type() != T::SYM) && lastType != -1) |
swissChili | 5d3e556 | 2022-02-24 16:49:19 -0800 | [diff] [blame] | 27 | out += " "; |
28 | |||||
29 | out += QString(v); | ||||
30 | } | ||||
31 | |||||
32 | return out; | ||||
33 | } | ||||
34 | |||||
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 35 | template <typename T> |
36 | QString pprint(QList<T> val) | ||||
37 | { | ||||
38 | QStringList out; | ||||
39 | |||||
40 | for (const T &v : val) | ||||
41 | out.append(static_cast<QString>(v)); | ||||
42 | |||||
43 | return out.join(" "); | ||||
44 | } | ||||
45 | |||||
46 | template <typename T> | ||||
47 | QString pprint(T val) | ||||
48 | { | ||||
49 | return static_cast<QString>(val); | ||||
50 | } | ||||
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame] | 51 | |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 52 | class PPrint |
53 | { | ||||
54 | public: | ||||
55 | enum Style | ||||
56 | { | ||||
57 | ANSI, | ||||
58 | HTML | ||||
59 | }; | ||||
60 | }; | ||||
61 | |||||
62 | QString pprint(ParseResult val, const Parser &parser, PPrint::Style style = PPrint::ANSI); | ||||
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame] | 63 | |
64 | void sout(QString string); | ||||
swissChili | 918557c | 2022-02-20 20:16:34 -0800 | [diff] [blame] | 65 | void eout(QString string); |