swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 1 | #pragma once |
2 | |||||
3 | #include <QList> | ||||
4 | #include <QChar> | ||||
5 | |||||
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 6 | template <typename T> |
7 | class TokenBase | ||||
8 | { | ||||
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 9 | public: |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 10 | TokenBase(); |
11 | TokenBase(const T &other); | ||||
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 12 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 13 | explicit TokenBase(QChar symbol); |
14 | explicit TokenBase(QString identifier); | ||||
15 | explicit TokenBase(QList<T> parenthesized); | ||||
16 | TokenBase(char varType, const QString name); | ||||
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 17 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 18 | bool operator==(const T &other) const; |
19 | bool operator!=(const T &other) const; | ||||
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 20 | |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame] | 21 | bool isSym() const; |
22 | bool isIdent() const; | ||||
23 | bool isParen() const; | ||||
24 | bool isVar() const; | ||||
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 25 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 26 | QList<T> parenContent(); |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 27 | |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 28 | char varType() const; |
29 | const QString &name() const; | ||||
swissChili | 682e7bc | 2021-12-07 09:04:54 -0800 | [diff] [blame] | 30 | QChar symbol() const; |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 31 | |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame] | 32 | operator QString() const; |
33 | |||||
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 34 | enum |
35 | { | ||||
36 | SYM, | ||||
37 | IDENT, | ||||
38 | PAREN, | ||||
39 | VAR, | ||||
40 | TOKEN_TYPE_LAST, | ||||
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 41 | }; |
42 | |||||
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame] | 43 | static QString typeToString(int type); |
44 | |||||
45 | int type() const; | ||||
46 | |||||
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 47 | protected: |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 48 | int _type = 0; |
49 | QString _stringVal = ""; | ||||
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 50 | QList<T> _listVal; |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 51 | QChar _charVal = 0; |
52 | }; | ||||
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 53 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 54 | class Token : public TokenBase<Token> |
55 | { | ||||
56 | public: | ||||
57 | using TokenBase::TokenBase; | ||||
58 | }; | ||||
59 | |||||
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 60 | using LTok = QList<Token>; |