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