1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use GetSky\ParserExpressions\RuleInterface; |
4
|
|
|
use GetSky\ParserExpressions\Rules\Any; |
5
|
|
|
use GetSky\ParserExpressions\Rules\AnyOf; |
6
|
|
|
use GetSky\ParserExpressions\Rules\EOI; |
7
|
|
|
use GetSky\ParserExpressions\Rules\FirstOf; |
8
|
|
|
use GetSky\ParserExpressions\Rules\OneOrMore; |
9
|
|
|
use GetSky\ParserExpressions\Rules\Optional; |
10
|
|
|
use GetSky\ParserExpressions\Rules\PredicateAnd; |
11
|
|
|
use GetSky\ParserExpressions\Rules\PredicateNot; |
12
|
|
|
use GetSky\ParserExpressions\Rules\Range; |
13
|
|
|
use GetSky\ParserExpressions\Rules\Sequence; |
14
|
|
|
use GetSky\ParserExpressions\Rules\Row; |
15
|
|
|
use GetSky\ParserExpressions\Rules\ZeroOrMore; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Syntactic sugar to create an object of class FirstOf. |
19
|
|
|
* |
20
|
|
|
* @param array $rules |
21
|
|
|
* @param string $name |
22
|
|
|
* @param callable $action |
23
|
|
|
* @return FirstOf |
24
|
|
|
*/ |
25
|
|
|
function FirstOf(array $rules, $name = "FirstOf", callable $action = null) |
26
|
|
|
{ |
27
|
|
|
return new FirstOf($rules, $name, $action); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Syntactic sugar to create an object of class OneOrMore. |
32
|
|
|
* |
33
|
|
|
* @param RuleInterface $rule |
34
|
|
|
* @param string $name |
35
|
|
|
* @param callable $action |
36
|
|
|
* @return OneOrMore |
37
|
|
|
*/ |
38
|
|
|
function OneOrMore($rule, $name = "OneOrMore", callable $action = null) |
39
|
|
|
{ |
40
|
|
|
return new OneOrMore($rule, $name, $action); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Syntactic sugar to create an object of class Optional. |
45
|
|
|
* |
46
|
|
|
* @param RuleInterface $rule |
47
|
|
|
* @param string $name |
48
|
|
|
* @param callable $action |
49
|
|
|
* @return Optional |
50
|
|
|
*/ |
51
|
|
|
function Optional($rule, $name = "Optional", callable $action = null) |
52
|
|
|
{ |
53
|
|
|
return new Optional($rule, $name, $action); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Syntactic sugar to create an object of class Sequence. |
58
|
|
|
* |
59
|
|
|
* @param array $rules |
60
|
|
|
* @param string $name |
61
|
|
|
* @param callable $action |
62
|
|
|
* @return Sequence |
63
|
|
|
*/ |
64
|
|
|
function Sequence(array $rules, $name = "Sequence", callable $action = null) |
65
|
|
|
{ |
66
|
|
|
return new Sequence($rules, $name, $action); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Syntactic sugar to create an object of class String. |
71
|
|
|
* |
72
|
|
|
* @param $string |
73
|
|
|
* @param string $name |
74
|
|
|
* @param callable $action |
75
|
|
|
* @return GetSky\ParserExpressions\Rules\Row |
76
|
|
|
*/ |
77
|
|
|
function Row($string, $name = "String", callable $action = null) |
78
|
|
|
{ |
79
|
|
|
return new Row($string, $name, $action); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Syntactic sugar to create an object of class ZeroOrMore. |
84
|
|
|
* |
85
|
|
|
* @param string|array|RuleInterface $rule |
86
|
|
|
* @param string $name |
87
|
|
|
* @param callable $action |
88
|
|
|
* @return ZeroOrMore |
89
|
|
|
*/ |
90
|
|
|
function ZeroOrMore($rule, $name = "ZeroOrMore", callable $action = null) |
91
|
|
|
{ |
92
|
|
|
return new ZeroOrMore($rule, $name, $action); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Syntactic sugar to create an object of class PredicateAnd. |
97
|
|
|
* |
98
|
|
|
* @param RuleInterface $rule |
99
|
|
|
* @param string $name |
100
|
|
|
* @return PredicateAnd |
101
|
|
|
*/ |
102
|
|
|
function PredicateAnd($rule, $name = "PredicateAnd") |
103
|
|
|
{ |
104
|
|
|
return new PredicateAnd($rule, $name); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Syntactic sugar to create an object of class PredicateNot. |
109
|
|
|
* |
110
|
|
|
* @param RuleInterface $rule |
111
|
|
|
* @param string $name |
112
|
|
|
* @return PredicateNot |
113
|
|
|
*/ |
114
|
|
|
function PredicateNot($rule, $name = "PredicateNot") |
115
|
|
|
{ |
116
|
|
|
return new PredicateNot($rule, $name); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Syntactic sugar to create an object of class Range. |
121
|
|
|
* |
122
|
|
|
* @param string|int $left |
123
|
|
|
* @param string|int $right |
124
|
|
|
* @param string $name |
125
|
|
|
* @param callable $action |
126
|
|
|
* @return Range |
127
|
|
|
*/ |
128
|
|
|
function CharRange($left, $right, $name = "Range", callable $action = null) |
129
|
|
|
{ |
130
|
|
|
return new Range($left, $right, $name, $action); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Syntactic sugar to create an object of class AnyOf. |
135
|
|
|
* |
136
|
|
|
* @param string|int $string |
137
|
|
|
* @param string $name |
138
|
|
|
* @return AnyOf |
139
|
|
|
*/ |
140
|
|
|
function AnyOf($string, $name = "AnyOf") |
141
|
|
|
{ |
142
|
|
|
return new Range($string, $name); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Syntactic sugar to create an object of class Any. |
147
|
|
|
* |
148
|
|
|
* @return PredicateNot |
149
|
|
|
*/ |
150
|
|
|
function Any() |
151
|
|
|
{ |
152
|
|
|
return new Any(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Syntactic sugar to create an object of class EOI. |
157
|
|
|
* |
158
|
|
|
* @return Eoi |
159
|
|
|
*/ |
160
|
|
|
function EOI() |
161
|
|
|
{ |
162
|
|
|
return new Eoi(); |
163
|
|
|
} |
164
|
|
|
|