aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testerrors.lua432
1 files changed, 257 insertions, 175 deletions
diff --git a/testerrors.lua b/testerrors.lua
index d39b8b9..1c5bb9f 100644
--- a/testerrors.lua
+++ b/testerrors.lua
@@ -23,6 +23,8 @@ function testerror(repatt, msg)
23 end 23 end
24end 24end
25 25
26-- testing NoPatt
27
26testerror([[~]], [[ 28testerror([[~]], [[
27L1:C1: no pattern found 29L1:C1: no pattern found
28~ 30~
@@ -35,6 +37,8 @@ L1:C1: no pattern found
35^ 37^
36]]) 38]])
37 39
40-- testing ExtraChars
41
38testerror([['p'~]], [[ 42testerror([['p'~]], [[
39L1:C4: unexpected characters after the pattern 43L1:C4: unexpected characters after the pattern
40'p'~ 44'p'~
@@ -47,6 +51,8 @@ L1:C5: unexpected characters after the pattern
47 ^ 51 ^
48]]) 52]])
49 53
54-- testing ExpPatt1
55
50testerror([['p' /{1}]], [[ 56testerror([['p' /{1}]], [[
51L1:C9: expected a pattern after '/' or the label(s) 57L1:C9: expected a pattern after '/' or the label(s)
52'p' /{1} 58'p' /{1}
@@ -71,6 +77,8 @@ L1:C6: expected a pattern after '/' or the label(s)
71 ^ 77 ^
72]]) 78]])
73 79
80-- testing ExpPatt2
81
74testerror([[&]], [[ 82testerror([[&]], [[
75L1:C2: expected a pattern after '&' 83L1:C2: expected a pattern after '&'
76& 84&
@@ -107,6 +115,8 @@ L1:C3: expected a pattern after '&'
107 ^ 115 ^
108]]) 116]])
109 117
118-- testing ExpPatt3
119
110testerror([[!]], [[ 120testerror([[!]], [[
111L1:C2: expected a pattern after '!' 121L1:C2: expected a pattern after '!'
112! 122!
@@ -143,6 +153,107 @@ L1:C3: expected a pattern after '!'
143 ^ 153 ^
144]]) 154]])
145 155
156-- testing ExpPatt4
157
158testerror([[()]], [[
159L1:C2: expected a pattern after '('
160()
161 ^
162]])
163
164testerror([[($$$)]], [[
165L1:C2: expected a pattern after '('
166($$$)
167 ^
168]])
169
170-- testing ExpPatt5
171
172testerror([[{: *** :}]], [[
173L1:C3: expected a pattern after ':'
174{: *** :}
175 ^
176]])
177
178testerror([[{:group: *** :}]], [[
179L1:C9: expected a pattern after ':'
180{:group: *** :}
181 ^
182]])
183
184testerror([[x <- {:x:}]], [[
185L1:C10: expected a pattern after ':'
186x <- {:x:}
187 ^
188]])
189
190-- testing ExpPatt6
191
192testerror([[{~~}]], [[
193L1:C3: expected a pattern after '{~'
194{~~}
195 ^
196]])
197
198testerror([[{ {~ } ~}]], [[
199L1:C5: expected a pattern after '{~'
200{ {~ } ~}
201 ^
202L1:C10: missing closing '}'
203{ {~ } ~}
204 ^
205]])
206
207testerror([[{~ ^_^ ~}]], [[
208L1:C3: expected a pattern after '{~'
209{~ ^_^ ~}
210 ^
211]])
212
213-- testing ExpPatt7
214
215testerror([[{||}]], [[
216L1:C3: expected a pattern after '{|'
217{||}
218 ^
219]])
220
221testerror([[{|@|}]], [[
222L1:C3: expected a pattern after '{|'
223{|@|}
224 ^
225]])
226
227-- testing ExpPatt8
228
229testerror([[S <-]], [[
230L1:C5: expected a pattern after '<-'
231S <-
232 ^
233]])
234
235testerror([[S <- 'p' T <-]], [[
236L1:C14: expected a pattern after '<-'
237S <- 'p' T <-
238 ^
239]])
240
241-- testing ExpPattOrClose
242
243testerror([[{0}]], [[
244L1:C2: expected a pattern or closing '}' after '{'
245{0}
246 ^
247]])
248
249testerror([[{ :'p': }]], [[
250L1:C2: expected a pattern or closing '}' after '{'
251{ :'p': }
252 ^
253]])
254
255-- testing ExpNum
256
146testerror([['p' ^ n]], [[ 257testerror([['p' ^ n]], [[
147L1:C6: expected a number after '^', '+' or '-' (no space) 258L1:C6: expected a number after '^', '+' or '-' (no space)
148'p' ^ n 259'p' ^ n
@@ -161,6 +272,8 @@ L1:C5: expected a number after '^', '+' or '-' (no space)
161 ^ 272 ^
162]]) 273]])
163 274
275-- testing ExpCap
276
164testerror([['p' -> {]], [[ 277testerror([['p' -> {]], [[
165L1:C7: expected a string, number, '{}' or name after '->' 278L1:C7: expected a string, number, '{}' or name after '->'
166'p' -> { 279'p' -> {
@@ -185,6 +298,8 @@ L1:C7: expected a string, number, '{}' or name after '->'
185 ^ 298 ^
186]]) 299]])
187 300
301-- testing ExpName1
302
188testerror([['p' =>]], [[ 303testerror([['p' =>]], [[
189L1:C7: expected the name of a rule after '=>' 304L1:C7: expected the name of a rule after '=>'
190'p' => 305'p' =>
@@ -197,24 +312,76 @@ L1:C7: expected the name of a rule after '=>'
197 ^ 312 ^
198]]) 313]])
199 314
200testerror([[()]], [[ 315-- testing ExpName2
201L1:C2: expected a pattern after '(' 316
202() 317testerror([['<' {:tag: [a-z]+ :} '>' '<' = '>']], [[
318L1:C31: expected the name of a rule after '=' (no space)
319'<' {:tag: [a-z]+ :} '>' '<' = '>'
320 ^
321]])
322
323testerror([['<' {:tag: [a-z]+ :} '>' '<' = tag '>']], [[
324L1:C31: expected the name of a rule after '=' (no space)
325'<' {:tag: [a-z]+ :} '>' '<' = tag '>'
326 ^
327]])
328
329-- testing ExpName3
330
331testerror([[<>]], [[
332L1:C2: expected the name of a rule after '<' (no space)
333<>
203 ^ 334 ^
204]]) 335]])
205 336
206testerror([[($$$)]], [[ 337testerror([[<123>]], [[
207L1:C2: expected a pattern after '(' 338L1:C2: expected the name of a rule after '<' (no space)
208($$$) 339<123>
209 ^ 340 ^
210]]) 341]])
211 342
212testerror([[('p' ('q' / 'r')]], [[ 343testerror([[< hello >]], [[
213L1:C17: missing closing ')' 344L1:C2: expected the name of a rule after '<' (no space)
214('p' ('q' / 'r') 345< hello >
215 ^ 346 ^
347]])
348
349testerror([[<<S>>]], [[
350L1:C2: expected the name of a rule after '<' (no space)
351<<S>>
352 ^
216]]) 353]])
217 354
355-- testing ExpLab1
356
357testerror([['p' /{} 'q']], [[
358L1:C7: expected at least one label after '{'
359'p' /{} 'q'
360 ^
361]])
362
363testerror([[%{ 'label' }]], [[
364L1:C3: expected at least one label after '{'
365%{ 'label' }
366 ^
367]])
368
369-- testing ExpLab2
370
371testerror([['p' /{1,2,3,} 'q']], [[
372L1:C13: expected a label after the comma
373'p' /{1,2,3,} 'q'
374 ^
375]])
376
377testerror([[%{ a,,b,,c }]], [[
378L1:C6: expected a label after the comma
379%{ a,,b,,c }
380 ^
381]])
382
383-- testing ExpNameOrLab
384
218testerror([[% s]], [[ 385testerror([[% s]], [[
219L1:C2: expected a name or label after '%' (no space) 386L1:C2: expected a name or label after '%' (no space)
220% s 387% s
@@ -227,18 +394,29 @@ L1:C2: expected a name or label after '%' (no space)
227 ^ 394 ^
228]]) 395]])
229 396
230testerror([[{: *** :}]], [[ 397-- testing ExpItem
231L1:C3: expected a pattern after ':' 398
232{: *** :} 399testerror([[
233 ^ 400"p" [
401abc
402] "q"
403]], [[
404L1:C6: expected at least one item after '[' or '^'
405"p" [
406 ^
234]]) 407]])
235 408
236testerror([[{:group: *** :}]], [[ 409-- testing MisClose1
237L1:C9: expected a pattern after ':' 410
238{:group: *** :} 411testerror([[('p' ('q' / 'r')]], [[
239 ^ 412L1:C17: missing closing ')'
413('p' ('q' / 'r')
414 ^
240]]) 415]])
241 416
417-- testing MisClose2
418
419-- two errors are reported due to the ignore strategy
242testerror([[{: group: 'p' :}]], [[ 420testerror([[{: group: 'p' :}]], [[
243L1:C9: missing closing ':}' 421L1:C9: missing closing ':}'
244{: group: 'p' :} 422{: group: 'p' :}
@@ -254,38 +432,7 @@ S <- {: 'p' T <- 'q'
254 ^ 432 ^
255]]) 433]])
256 434
257testerror([['<' {:tag: [a-z]+ :} '>' '<' = '>']], [[ 435-- testing MisClose3
258L1:C31: expected the name of a rule after '=' (no space)
259'<' {:tag: [a-z]+ :} '>' '<' = '>'
260 ^
261]])
262
263testerror([['<' {:tag: [a-z]+ :} '>' '<' = tag '>']], [[
264L1:C31: expected the name of a rule after '=' (no space)
265'<' {:tag: [a-z]+ :} '>' '<' = tag '>'
266 ^
267]])
268
269testerror([[{~~}]], [[
270L1:C3: expected a pattern after '{~'
271{~~}
272 ^
273]])
274
275testerror([[{ {~ } ~}]], [[
276L1:C5: expected a pattern after '{~'
277{ {~ } ~}
278 ^
279L1:C10: missing closing '}'
280{ {~ } ~}
281 ^
282]])
283
284testerror([[{~ ^_^ ~}]], [[
285L1:C3: expected a pattern after '{~'
286{~ ^_^ ~}
287 ^
288]])
289 436
290testerror([['p' {~ ('q' 'r') / 's']], [[ 437testerror([['p' {~ ('q' 'r') / 's']], [[
291L1:C23: missing closing '~}' 438L1:C23: missing closing '~}'
@@ -293,47 +440,27 @@ L1:C23: missing closing '~}'
293 ^ 440 ^
294]]) 441]])
295 442
296testerror([[{0}]], [[ 443-- testing MisClose4
297L1:C2: expected a pattern or closing '}' after '{'
298{0}
299 ^
300]])
301 444
302testerror([[{ :'p': }]], [[ 445-- two errors are reported due to the ignore strategy
303L1:C2: expected a pattern or closing '}' after '{' 446testerror([['p' {| 'q' / 'r' }]], [[
304{ :'p': } 447L1:C17: missing closing '|}'
305 ^ 448'p' {| 'q' / 'r' }
449 ^
450L1:C18: unexpected characters after the pattern
451'p' {| 'q' / 'r' }
452 ^
306]]) 453]])
307 454
455-- testing MisClose5
456
308testerror([[{ 'p' ]], [[ 457testerror([[{ 'p' ]], [[
309L1:C6: missing closing '}' 458L1:C6: missing closing '}'
310{ 'p' 459{ 'p'
311 ^ 460 ^
312]]) 461]])
313 462
314testerror([[<>]], [[ 463-- testing MisClose6
315L1:C2: expected the name of a rule after '<' (no space)
316<>
317 ^
318]])
319
320testerror([[<123>]], [[
321L1:C2: expected the name of a rule after '<' (no space)
322<123>
323 ^
324]])
325
326testerror([[< hello >]], [[
327L1:C2: expected the name of a rule after '<' (no space)
328< hello >
329 ^
330]])
331
332testerror([[<<S>>]], [[
333L1:C2: expected the name of a rule after '<' (no space)
334<<S>>
335 ^
336]])
337 464
338testerror([[<patt]], [[ 465testerror([[<patt]], [[
339L1:C6: missing closing '>' 466L1:C6: missing closing '>'
@@ -347,18 +474,16 @@ L1:C8: missing closing '>'
347 ^ 474 ^
348]]) 475]])
349 476
350testerror([[S <-]], [[ 477-- testing MisClose7
351L1:C5: expected a pattern after '<-'
352S <-
353 ^
354]])
355 478
356testerror([[S <- 'p' T <-]], [[ 479testerror([['{' %{ a, b '}']], [[
357L1:C14: expected a pattern after '<-' 480L1:C12: missing closing '}'
358S <- 'p' T <- 481'{' %{ a, b '}'
359 ^ 482 ^
360]]) 483]])
361 484
485-- testing MisClose8
486
362testerror([[[]], [[ 487testerror([[[]], [[
363L1:C1: missing closing ']' 488L1:C1: missing closing ']'
364[ 489[
@@ -389,41 +514,7 @@ L1:C1: missing closing ']'
389^ 514^
390]]) 515]])
391 516
392testerror([['p' /{} 'q']], [[ 517-- testing MisTerm1
393L1:C7: expected at least one label after '{'
394'p' /{} 'q'
395 ^
396]])
397
398testerror([[%{ 'label' }]], [[
399L1:C3: expected at least one label after '{'
400%{ 'label' }
401 ^
402]])
403
404testerror([['p' /{1,2,3,} 'q']], [[
405L1:C13: expected a label after the comma
406'p' /{1,2,3,} 'q'
407 ^
408]])
409
410testerror([[%{ a,,b,,c }]], [[
411L1:C6: expected a label after the comma
412%{ a,,b,,c }
413 ^
414]])
415
416testerror([['{' %{ a, b '}']], [[
417L1:C12: missing closing '}'
418'{' %{ a, b '}'
419 ^
420]])
421
422testerror([[Q <- "To be or not to be...]], [[
423L1:C6: missing terminating double quote
424Q <- "To be or not to be...
425 ^
426]])
427 518
428testerror([['That is the question...]], [[ 519testerror([['That is the question...]], [[
429L1:C1: missing terminating single quote 520L1:C1: missing terminating single quote
@@ -431,32 +522,16 @@ L1:C1: missing terminating single quote
431^ 522^
432]]) 523]])
433 524
434testerror([[{||}]], [[ 525-- testing MisTerm2
435L1:C3: expected a pattern after '{|'
436{||}
437 ^
438]])
439 526
440testerror([[{|@|}]], [[ 527testerror([[Q <- "To be or not to be...]], [[
441L1:C3: expected a pattern after '{|' 528L1:C6: missing terminating double quote
442{|@|} 529Q <- "To be or not to be...
443 ^ 530 ^
444]])
445
446testerror([['p' {| 'q' / 'r' }]], [[
447L1:C17: missing closing '|}'
448'p' {| 'q' / 'r' }
449 ^
450L1:C18: unexpected characters after the pattern
451'p' {| 'q' / 'r' }
452 ^
453]]) 531]])
454 532
455testerror([[x <- {:x:}]], [[ 533-- testing error recovery, more complex grammars (multiline),
456L1:C10: expected a pattern after ':' 534-- and pointer positions in error recovery
457x <- {:x:}
458 ^
459]])
460 535
461testerror([[&'p'/&/!/'p'^'q']], [[ 536testerror([[&'p'/&/!/'p'^'q']], [[
462L1:C7: expected a pattern after '&' 537L1:C7: expected a pattern after '&'
@@ -483,32 +558,6 @@ L2:C15: expected a pattern after '!'
483 ^ 558 ^
484]]) 559]])
485 560
486testerror([[
487 A <- %nosuch %def
488 A <- 'A again'
489 A <- 'and again'
490]], [[
491name 'nosuch' undefined
492]])
493
494testerror([[names not in grammar]], [[
495rule 'names' used outside a grammar
496]])
497
498testerror([[
499 A <- %nosuch %def
500 A <- 'A again'
501 A <- 'and again'
502]], [[
503name 'nosuch' undefined
504]])
505
506testerror([[ A <- %nosuch ('error' ]], [[
507L1:C23: missing closing ')'
508 A <- %nosuch ('error'
509 ^
510]])
511
512testerror([['a' / &@ ('c' / 'd')]], [[ 561testerror([['a' / &@ ('c' / 'd')]], [[
513L1:C8: expected a pattern after '&' 562L1:C8: expected a pattern after '&'
514'a' / &@ ('c' / 'd') 563'a' / &@ ('c' / 'd')
@@ -568,6 +617,8 @@ L1:C12: missing closing ')'
568 ^ 617 ^
569]]) 618]])
570 619
620-- an unfortunate second error exists because we don't know
621-- what's part of the quotation
571testerror([[ 622testerror([[
572 X <- ('p / Q (R 623 X <- ('p / Q (R
573 / S)) 624 / S))
@@ -616,4 +667,35 @@ L1:C13: expected a pattern after '&'
616 ^ 667 ^
617]]) 668]])
618 669
670-- testing non-syntax errors
671
672testerror([[
673 A <- %nosuch %def
674 A <- 'A again'
675 A <- 'and again'
676]], [[
677name 'nosuch' undefined
678]])
679
680testerror([[names not in grammar]], [[
681rule 'names' used outside a grammar
682]])
683
684testerror([[
685 A <- %nosuch %def
686 A <- 'A again'
687 A <- 'and again'
688]], [[
689name 'nosuch' undefined
690]])
691
692-- the non-syntax error should not be reported
693-- since there is a syntax error
694testerror([[ A <- %nosuch ('error' ]], [[
695L1:C23: missing closing ')'
696 A <- %nosuch ('error'
697 ^
698]])
699
700
619print 'OK' 701print 'OK'