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