-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunction.h
48 lines (36 loc) · 1002 Bytes
/
Function.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#include "Token.h"
#include "AstNode.h"
#include "VarContext.h"
#include "Matcher.h"
using SentenceResultFn = std::function<QList<Token> (VarContext)>;
class Sentence {
public:
Sentence() = default;
~Sentence();
Sentence(QList<Token> pattern, QList<AstNode> result);
Sentence(QList<Token> pattern, SentenceResultFn result);
bool isExternal() const;
QList<Token> externResult(MatchResult args) const;
QList<Token> pattern() const;
QList<AstNode> result() const;
operator QString() const;
protected:
QList<Token> _pattern;
QList<AstNode> _result;
SentenceResultFn _native = nullptr;
};
class Function {
public:
Function() = default;
explicit Function(QString name);
Function(QString name, QList<Sentence> sentences);
void addSentence(Sentence sentence);
void addNativeSentence(QString pattern, SentenceResultFn fn);
QString name() const;
QList<Sentence> sentences() const;
operator QString() const;
private:
QString _name;
QList<Sentence> _sentences;
};