forked from ingydotnet/testml-pgx
/
testml.pgx
236 lines (181 loc) · 3.95 KB
/
testml.pgx
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
testml_document:
code_section
data_section?
# General Tokens
escape: / [0nt] /
line: / <ANY>* <EOL> /
blank_line: / <BLANK>* <EOL> /
comment: / <HASH> <line> /
ws: /(:
<BLANK> |
<EOL> |
<comment>
)/
# Strings
quoted_string:
single_quoted_string |
double_quoted_string
single_quoted_string:
/(:
<SINGLE>
((:
[^<BREAK><BACK><SINGLE>] |
<BACK><SINGLE> |
<BACK><BACK>
)*?)
<SINGLE>
)/
double_quoted_string:
/(:
<DOUBLE>
((:
[^<BREAK><BACK><DOUBLE>] |
<BACK><DOUBLE> |
<BACK><BACK> |
<BACK><escape>
)*?)
<DOUBLE>
)/
unquoted_string:
/(
[^<BLANKS><BREAK><HASH>]
(:
[^<BREAK><HASH>]*
[^<BLANKS><BREAK><HASH>]
)?
)/
number: / (<DIGIT>+) /
# TestML Code Section
code_section: (
~~ |
assignment_statement |
code_statement
)*
assignment_statement:
variable_name
/<WS>+ <EQUAL> <WS>+/
code_expression
semicolon
variable_name: /(<ALPHA><WORD>*)/
code_statement:
code_expression
assertion_call?
semicolon
semicolon:
/<SEMI>/ |
`You seem to be missing a semicolon`
code_expression:
code_object
unit_call*
unit_call:
!assertion_call_test
call_indicator
code_object
code_object:
function_object |
point_object |
string_object |
number_object |
transform_object
function_object:
function_signature?
function_start
( ~~ | assignment_statement | code_statement )*
/ ~ <RCURLY> /
function_start: / ~ (<LCURLY>) ~ /
function_signature:
/<LPAREN>~/
function_variables?
/~<RPAREN>/
function_variables:
function_variable+ % / ~ <COMMA> ~ /
function_variable: /(<ALPHA><WORD>*)/
point_object: /(<STAR> <LOWER><WORD>*)/
string_object: quoted_string
number_object: number
transform_object:
transform_name
transform_argument_list?
transform_name: user_transform | core_transform
user_transform: /(<LOWER><WORD>*)/
core_transform: /(<UPPER><WORD>*)/
call_indicator: /(: <DOT> ~ | ~ <DOT> )/
transform_argument_list:
/ <LPAREN> ~ /
transform_argument* % / ~ <COMMA> ~ /
/ ~ <RPAREN> /
transform_argument: code_expression
assertion_call_test: / <call_indicator> (: EQ|OK|HAS ) /
assertion_call:
+assertion_eq |
+assertion_ok |
+assertion_has
assertion_eq:
+assertion_operator_eq |
+assertion_function_eq
assertion_operator_eq:
/ ~~ <EQUAL><EQUAL> ~~ /
code_expression
assertion_function_eq:
/ <call_indicator> EQ <LPAREN> /
code_expression
/ <RPAREN> /
assertion_ok: assertion_function_ok
assertion_function_ok: / <call_indicator> (OK) <empty_parens>? /
assertion_has: +assertion_operator_has | +assertion_function_has
assertion_operator_has:
/ ~~ <TILDE><TILDE> ~~ /
code_expression
assertion_function_has:
/ <call_indicator> HAS <LPAREN> /
code_expression
/ <RPAREN> /
empty_parens: /(: <LPAREN> ~ <RPAREN> )/
# TestML Data Section
data_section: data_block*
data_block:
block_header
.( blank_line | comment )*
block_point*
block_header:
block_marker
( / <BLANK>+ / block_label )?
/ <BLANK>* <EOL> /
block_marker: / <EQUAL><EQUAL><EQUAL> /
block_label: unquoted_string
block_point: lines_point | phrase_point
lines_point:
point_marker
/ <BLANK>+ /
point_name
/ <BLANK>* <EOL> /
point_lines
point_lines: /(
(:
(!
<block_marker> |
<point_marker>
)
<line>
)*
)/
phrase_point:
point_marker
/ <BLANK>+ /
point_name
/ <COLON> <BLANK> /
point_phrase
/ <EOL> /
/(:
<comment> |
<blank_line>
)*/
point_marker: / <DASH><DASH><DASH> /
point_name:
/(
<user_point_name> |
<core_point_name>
)/
user_point_name: / <LOWER><WORD>* /
core_point_name: / <UPPER><WORD>* /
point_phrase: unquoted_string