-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pattern.cpp
61 lines (60 loc) · 1.54 KB
/
Pattern.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Pattern.h"
#include "Node.h"
namespace yfpeg {
//And
Pattern& Pattern::operator*(Pattern& rvalue) {
AndNode* newNode = new AndNode();
newNode->addChild(pNode);
newNode->addChild(rvalue.pNode);
return *new Pattern(newNode);
}
//Or
Pattern& Pattern::operator+(Pattern& rvalue) {
OrNode* newNode = new OrNode();
newNode->addChild(pNode);
newNode->addChild(rvalue.pNode);
return *new Pattern(newNode);
}
//Not
Pattern& Pattern::operator-(Pattern& rvalue) {
AndNode* newNode = new AndNode();
NotNode* notNode = new NotNode(rvalue.pNode);
newNode->addChild(notNode);
newNode->addChild(this->pNode);
return *new Pattern(newNode);
}
//Assign
Pattern& Pattern::operator=(Pattern& rvalue) {
ReferenceNode* refNode = CAST_TO(this->pNode, ReferenceNode);
if (refNode)
{
refNode->setInnerNode(rvalue.pNode);
}
else {
this->pNode = rvalue.pNode;
}
return *this;
};
//Capture
Pattern& Pattern::operator<<(string tag) {
return *new Pattern(new CaptureNode(this->pNode,tag));
};
Pattern& Pattern::operator>>(FILTER_TYPE filterType) {
return *new Pattern(new FilterNode(this->pNode,filterType));
};
//atLeast or atMost
Pattern& Pattern::operator^(int times) {
RepeatNode* repeat = nullptr;
if (times >= 0) {
repeat = new RepeatNode(this->pNode,times,true);
}
else {
repeat = new RepeatNode(this->pNode,-times,false);
}
return *new Pattern(repeat);
}
//Callback
Pattern& Pattern::operator/(Pattern& rvalue) {
return *this;
}
}