blob: 2cb862f6598fe031fd37e9f90dde2f63de45f058 [file] [log] [blame]
swissChili8a581c62021-12-07 13:29:21 -08001#pragma once
2
3#include "Token.h"
4#include "AstNode.h"
5
swissChili323883d2022-02-20 16:35:23 -08006using SentenceResultFn = std::function<QList<Token> (QList<Token>)>;
7
swissChili8a581c62021-12-07 13:29:21 -08008class Sentence {
9public:
10 Sentence() = default;
swissChili323883d2022-02-20 16:35:23 -080011 ~Sentence();
swissChili8a581c62021-12-07 13:29:21 -080012 Sentence(QList<Token> pattern, QList<AstNode> result);
swissChili323883d2022-02-20 16:35:23 -080013 Sentence(QList<Token> pattern, SentenceResultFn result);
14
15 bool isExternal() const;
16 QList<Token> externResult(QList<Token> args) const;
swissChili8a581c62021-12-07 13:29:21 -080017
18 QList<Token> pattern() const;
19 QList<AstNode> result() const;
20
21 operator QString() const;
22
23protected:
24 QList<Token> _pattern;
25 QList<AstNode> _result;
swissChili323883d2022-02-20 16:35:23 -080026 SentenceResultFn _native = nullptr;
swissChili8a581c62021-12-07 13:29:21 -080027};
28
29class Function {
30public:
31 Function() = default;
32 explicit Function(QString name);
33 Function(QString name, QList<Sentence> sentences);
34
35 void addSentence(Sentence sentence);
swissChili323883d2022-02-20 16:35:23 -080036 void addNativeSentence(QString pattern, SentenceResultFn fn);
swissChili8a581c62021-12-07 13:29:21 -080037
38 QString name() const;
39 QList<Sentence> sentences() const;
40
41 operator QString() const;
42
43private:
44 QString _name;
45 QList<Sentence> _sentences;
46};