blob: 6e0450c7b7ba2efcb07abaa117f8b23531fb41f4 [file] [log] [blame]
swissChili7babd922021-12-02 22:46:48 -08001#pragma once
2
3#include <QList>
4#include <QChar>
5
swissChilic71acc62021-12-07 08:03:37 -08006template <typename T>
7class TokenBase
8{
swissChili7babd922021-12-02 22:46:48 -08009public:
swissChilic71acc62021-12-07 08:03:37 -080010 TokenBase();
11 TokenBase(const T &other);
swissChili7babd922021-12-02 22:46:48 -080012
swissChili9dddbf72021-12-08 23:03:25 -080013 TokenBase(QString integer, int base);
swissChilic71acc62021-12-07 08:03:37 -080014 explicit TokenBase(QChar symbol);
15 explicit TokenBase(QString identifier);
16 explicit TokenBase(QList<T> parenthesized);
17 TokenBase(char varType, const QString name);
swissChili7babd922021-12-02 22:46:48 -080018
swissChilic71acc62021-12-07 08:03:37 -080019 bool operator==(const T &other) const;
20 bool operator!=(const T &other) const;
swissChili7babd922021-12-02 22:46:48 -080021
swissChilid17b5a12021-12-05 20:46:42 -080022 bool isSym() const;
23 bool isIdent() const;
24 bool isParen() const;
25 bool isVar() const;
swissChili9dddbf72021-12-08 23:03:25 -080026 bool isInteger() const;
swissChili7babd922021-12-02 22:46:48 -080027
swissChilic71acc62021-12-07 08:03:37 -080028 QList<T> parenContent();
swissChili7babd922021-12-02 22:46:48 -080029
swissChili3e98c062021-12-04 22:07:38 -080030 char varType() const;
31 const QString &name() const;
swissChili682e7bc2021-12-07 09:04:54 -080032 QChar symbol() const;
swissChili9dddbf72021-12-08 23:03:25 -080033 int integer() const;
swissChili3e98c062021-12-04 22:07:38 -080034
swissChilid17b5a12021-12-05 20:46:42 -080035 operator QString() const;
36
swissChilic71acc62021-12-07 08:03:37 -080037 enum
38 {
39 SYM,
40 IDENT,
41 PAREN,
42 VAR,
swissChili9dddbf72021-12-08 23:03:25 -080043 INTEGER,
swissChilic71acc62021-12-07 08:03:37 -080044 TOKEN_TYPE_LAST,
swissChili7babd922021-12-02 22:46:48 -080045 };
46
swissChilid17b5a12021-12-05 20:46:42 -080047 static QString typeToString(int type);
48
49 int type() const;
50
swissChilic71acc62021-12-07 08:03:37 -080051protected:
swissChili7babd922021-12-02 22:46:48 -080052 int _type = 0;
swissChili9dddbf72021-12-08 23:03:25 -080053 int _intVal = 0;
swissChili7babd922021-12-02 22:46:48 -080054 QString _stringVal = "";
swissChilic71acc62021-12-07 08:03:37 -080055 QList<T> _listVal;
swissChili7babd922021-12-02 22:46:48 -080056 QChar _charVal = 0;
57};
swissChili3e98c062021-12-04 22:07:38 -080058
swissChilic71acc62021-12-07 08:03:37 -080059class Token : public TokenBase<Token>
60{
61public:
62 using TokenBase::TokenBase;
63};
64
swissChili3e98c062021-12-04 22:07:38 -080065using LTok = QList<Token>;