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