blob: fb567012db90ef5566ec18e9d84119aa2b4593c7 [file] [log] [blame]
swissChilic71acc62021-12-07 08:03:37 -08001#pragma once
2
3#include <QString>
4
swissChili682e7bc2021-12-07 09:04:54 -08005#include "Token.h"
swissChilic71acc62021-12-07 08:03:37 -08006#include "AstNode.h"
7
8class Parser
9{
10public:
11 explicit Parser(QString input);
12
13 QChar peek();
14 QChar get();
15 bool atEnd();
16
17 void skip();
18
swissChili682e7bc2021-12-07 09:04:54 -080019 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
swissChilic71acc62021-12-07 08:03:37 -080034 bool parseFunction(AstNode *node);
swissChili682e7bc2021-12-07 09:04:54 -080035
36 template <typename T>
37 QList<T> parseMany();
38
39 template <typename T>
40 bool parseOne(T *node);
swissChilic71acc62021-12-07 08:03:37 -080041
42private:
43 int _pos = 0;
44 QString _input;
45};
swissChili682e7bc2021-12-07 09:04:54 -080046
47template <>
48bool Parser::parseOne<Token>(Token *node);
49
50template <>
51bool Parser::parseOne<AstNode>(AstNode *node);