blob: 14269890eac6ee81896435d36f02166657a5f87d [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"
swissChili8a581c62021-12-07 13:29:21 -08007#include "Function.h"
swissChilic71acc62021-12-07 08:03:37 -08008
9class Parser
10{
11public:
12 explicit Parser(QString input);
13
14 QChar peek();
15 QChar get();
16 bool atEnd();
17
18 void skip();
19
swissChili682e7bc2021-12-07 09:04:54 -080020 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
swissChilic71acc62021-12-07 08:03:37 -080035 bool parseFunction(AstNode *node);
swissChili682e7bc2021-12-07 09:04:54 -080036
37 template <typename T>
38 QList<T> parseMany();
39
40 template <typename T>
41 bool parseOne(T *node);
swissChilic71acc62021-12-07 08:03:37 -080042
swissChili8a581c62021-12-07 13:29:21 -080043 bool parseSentence(Sentence *sentence);
44 bool parseFunctionDefinition(Function *function);
45
swissChilic71acc62021-12-07 08:03:37 -080046private:
47 int _pos = 0;
48 QString _input;
49};
swissChili682e7bc2021-12-07 09:04:54 -080050
51template <>
52bool Parser::parseOne<Token>(Token *node);
53
54template <>
55bool Parser::parseOne<AstNode>(AstNode *node);