blob: 75c445553a43c98cbbd0d98b3f38a4dc60294a9a [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
swissChilic71acc62021-12-07 08:03:37 -080013 explicit TokenBase(QChar symbol);
14 explicit TokenBase(QString identifier);
15 explicit TokenBase(QList<T> parenthesized);
16 TokenBase(char varType, const QString name);
swissChili7babd922021-12-02 22:46:48 -080017
swissChilic71acc62021-12-07 08:03:37 -080018 bool operator==(const T &other) const;
19 bool operator!=(const T &other) const;
swissChili7babd922021-12-02 22:46:48 -080020
swissChilid17b5a12021-12-05 20:46:42 -080021 bool isSym() const;
22 bool isIdent() const;
23 bool isParen() const;
24 bool isVar() const;
swissChili7babd922021-12-02 22:46:48 -080025
swissChilic71acc62021-12-07 08:03:37 -080026 QList<T> parenContent();
swissChili7babd922021-12-02 22:46:48 -080027
swissChili3e98c062021-12-04 22:07:38 -080028 char varType() const;
29 const QString &name() const;
swissChili682e7bc2021-12-07 09:04:54 -080030 QChar symbol() const;
swissChili3e98c062021-12-04 22:07:38 -080031
swissChilid17b5a12021-12-05 20:46:42 -080032 operator QString() const;
33
swissChilic71acc62021-12-07 08:03:37 -080034 enum
35 {
36 SYM,
37 IDENT,
38 PAREN,
39 VAR,
40 TOKEN_TYPE_LAST,
swissChili7babd922021-12-02 22:46:48 -080041 };
42
swissChilid17b5a12021-12-05 20:46:42 -080043 static QString typeToString(int type);
44
45 int type() const;
46
swissChilic71acc62021-12-07 08:03:37 -080047protected:
swissChili7babd922021-12-02 22:46:48 -080048 int _type = 0;
49 QString _stringVal = "";
swissChilic71acc62021-12-07 08:03:37 -080050 QList<T> _listVal;
swissChili7babd922021-12-02 22:46:48 -080051 QChar _charVal = 0;
52};
swissChili3e98c062021-12-04 22:07:38 -080053
swissChilic71acc62021-12-07 08:03:37 -080054class Token : public TokenBase<Token>
55{
56public:
57 using TokenBase::TokenBase;
58};
59
swissChili3e98c062021-12-04 22:07:38 -080060using LTok = QList<Token>;