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 | 918557c | 2022-02-20 20:16:34 -0800 | [diff] [blame] | 15 | //template <> |
| 16 | //QString pprint<Token>(Token val); |
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 17 | |
swissChili | 918557c | 2022-02-20 20:16:34 -0800 | [diff] [blame] | 18 | //template <> |
| 19 | //QString pprint<AstNode>(AstNode val); |
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 20 | |
swissChili | 5d3e556 | 2022-02-24 16:49:19 -0800 | [diff] [blame] | 21 | template <typename T, typename std::enable_if_t<std::is_base_of<TokenBase<T>, T>::value>::value = true> |
| 22 | QString pprint(QList<T> val) |
| 23 | { |
| 24 | QString out; |
| 25 | int lastType = -1; |
| 26 | |
| 27 | qInfo() << "pprint specialized"; |
| 28 | |
| 29 | for (const T &v : val) |
| 30 | { |
| 31 | if ((lastType != v.type() || v.type() != T::SYMBOL) && lastType != -1) |
| 32 | out += " "; |
| 33 | |
| 34 | out += QString(v); |
| 35 | } |
| 36 | |
| 37 | return out; |
| 38 | } |
| 39 | |
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 40 | template <typename T> |
| 41 | QString pprint(QList<T> val) |
| 42 | { |
| 43 | QStringList out; |
| 44 | |
| 45 | for (const T &v : val) |
| 46 | out.append(static_cast<QString>(v)); |
| 47 | |
| 48 | return out.join(" "); |
| 49 | } |
| 50 | |
| 51 | template <typename T> |
| 52 | QString pprint(T val) |
| 53 | { |
| 54 | return static_cast<QString>(val); |
| 55 | } |
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame] | 56 | |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame^] | 57 | class PPrint |
| 58 | { |
| 59 | public: |
| 60 | enum Style |
| 61 | { |
| 62 | ANSI, |
| 63 | HTML |
| 64 | }; |
| 65 | }; |
| 66 | |
| 67 | QString pprint(ParseResult val, const Parser &parser, PPrint::Style style = PPrint::ANSI); |
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame] | 68 | |
| 69 | void sout(QString string); |
swissChili | 918557c | 2022-02-20 20:16:34 -0800 | [diff] [blame] | 70 | void eout(QString string); |