swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <QString> |
| 4 | |
swissChili | 682e7bc | 2021-12-07 09:04:54 -0800 | [diff] [blame^] | 5 | #include "Token.h" |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 6 | #include "AstNode.h" |
| 7 | |
| 8 | class Parser |
| 9 | { |
| 10 | public: |
| 11 | explicit Parser(QString input); |
| 12 | |
| 13 | QChar peek(); |
| 14 | QChar get(); |
| 15 | bool atEnd(); |
| 16 | |
| 17 | void skip(); |
| 18 | |
swissChili | 682e7bc | 2021-12-07 09:04:54 -0800 | [diff] [blame^] | 19 | template <typename T> |
| 20 | bool parseSymbol(T *node); |
| 21 | |
| 22 | template <typename T> |
| 23 | bool parseIdentifier(T *node); |
| 24 | |
| 25 | template <typename T> |
| 26 | bool parseNumber(T *node); |
| 27 | |
| 28 | template <typename T> |
| 29 | bool parseVariable(T *node); |
| 30 | |
| 31 | template <typename T> |
| 32 | bool parseParens(T *node); |
| 33 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 34 | bool parseFunction(AstNode *node); |
swissChili | 682e7bc | 2021-12-07 09:04:54 -0800 | [diff] [blame^] | 35 | |
| 36 | template <typename T> |
| 37 | QList<T> parseMany(); |
| 38 | |
| 39 | template <typename T> |
| 40 | bool parseOne(T *node); |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 41 | |
| 42 | private: |
| 43 | int _pos = 0; |
| 44 | QString _input; |
| 45 | }; |
swissChili | 682e7bc | 2021-12-07 09:04:54 -0800 | [diff] [blame^] | 46 | |
| 47 | template <> |
| 48 | bool Parser::parseOne<Token>(Token *node); |
| 49 | |
| 50 | template <> |
| 51 | bool Parser::parseOne<AstNode>(AstNode *node); |