swissChili | 8a581c6 | 2021-12-07 13:29:21 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "Token.h" |
| 4 | #include "AstNode.h" |
| 5 | |
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame^] | 6 | using SentenceResultFn = std::function<QList<Token> (QList<Token>)>; |
| 7 | |
swissChili | 8a581c6 | 2021-12-07 13:29:21 -0800 | [diff] [blame] | 8 | class Sentence { |
| 9 | public: |
| 10 | Sentence() = default; |
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame^] | 11 | ~Sentence(); |
swissChili | 8a581c6 | 2021-12-07 13:29:21 -0800 | [diff] [blame] | 12 | Sentence(QList<Token> pattern, QList<AstNode> result); |
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame^] | 13 | Sentence(QList<Token> pattern, SentenceResultFn result); |
| 14 | |
| 15 | bool isExternal() const; |
| 16 | QList<Token> externResult(QList<Token> args) const; |
swissChili | 8a581c6 | 2021-12-07 13:29:21 -0800 | [diff] [blame] | 17 | |
| 18 | QList<Token> pattern() const; |
| 19 | QList<AstNode> result() const; |
| 20 | |
| 21 | operator QString() const; |
| 22 | |
| 23 | protected: |
| 24 | QList<Token> _pattern; |
| 25 | QList<AstNode> _result; |
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame^] | 26 | SentenceResultFn _native = nullptr; |
swissChili | 8a581c6 | 2021-12-07 13:29:21 -0800 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | class Function { |
| 30 | public: |
| 31 | Function() = default; |
| 32 | explicit Function(QString name); |
| 33 | Function(QString name, QList<Sentence> sentences); |
| 34 | |
| 35 | void addSentence(Sentence sentence); |
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame^] | 36 | void addNativeSentence(QString pattern, SentenceResultFn fn); |
swissChili | 8a581c6 | 2021-12-07 13:29:21 -0800 | [diff] [blame] | 37 | |
| 38 | QString name() const; |
| 39 | QList<Sentence> sentences() const; |
| 40 | |
| 41 | operator QString() const; |
| 42 | |
| 43 | private: |
| 44 | QString _name; |
| 45 | QList<Sentence> _sentences; |
| 46 | }; |