aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testerrors.lua759
1 files changed, 604 insertions, 155 deletions
diff --git a/testerrors.lua b/testerrors.lua
index 6e9c83e..afa80c6 100644
--- a/testerrors.lua
+++ b/testerrors.lua
@@ -1,161 +1,610 @@
1local re = require 'relabel' 1local re = require 'relabel'
2 2
3local npass, ntests = 0, 0 3function testerror(repatt, msg)
4 4 msg = msg:match("^%s*(.-)%s*$") -- trim
5function testerror(repatt)
6 ntests = ntests + 1
7 local ok, err = pcall(function () re.compile(repatt) end) 5 local ok, err = pcall(function () re.compile(repatt) end)
8 6 assert(not ok)
9 if ok then 7 err = err:match("^[^\n]*\n(.-)$") -- remove first line (filename)
10 print("FAIL", ntests) 8 err = err:gsub(" *\n", "\n") -- remove trailing spaces
11 else 9 -- if err ~= msg then
12 npass = npass + 1 10 -- print(#err, #msg)
13 print("PASS", ntests, err) 11 -- print('--')
14 end 12 -- print(err)
13 -- print('--')
14 -- print(msg)
15 -- print('--')
16 -- end
17 assert(err == msg)
15end 18end
16 19
17local patterns = { 20testerror([[~]],[[
18 -- 1-5 21L1:C1: no pattern found
19 [[~]], 22~
20 [[???]], 23^
21 [['p'~]], 24]])
22 [['p'?$?]], 25
23 [['p' /{1}]], 26testerror([[???]], [[
24 -- 6-10 27L1:C1: no pattern found
25 [['p' /{1} /{2} 'q']], 28???
26 [['p' /]], 29^
27 [['p' / / 'q']], 30]])
28 [[&]], 31
29 [[& / 'p']], 32testerror([['p'~]], [[
30 -- 11-15 33L1:C4: unexpected characters after the pattern
31 [['p' &]], 34'p'~
32 [['p' / & / 'q']], 35 ^
33 [[&&]], 36]])
34 [[!&]], 37
35 [[!]], 38testerror([['p'?$?]], [[
36 -- 16-20 39L1:C5: unexpected characters after the pattern
37 [[! / 'p']], 40'p'?$?
38 [['p' !]], 41 ^
39 [['p' / ! / 'q']], 42]])
40 [[!!]], 43
41 [[&!]], 44testerror([['p' /{1}]], [[
42 -- 21-25 45L1:C9: expected a pattern after '/' or the label(s)
43 [['p' ^ n]], 46'p' /{1}
44 [['p'^+(+1)]], 47 ^
45 [['p'^-/'q']], 48]])
46 [['p' -> {]], 49
47 [['p' -> {'q'}]], 50testerror([['p' /{1} /{2} 'q']], [[
48 -- 26-30 51L1:C9: expected a pattern after '/' or the label(s)
49 [['p' -> / 'q']], 52'p' /{1} /{2} 'q'
50 [['p' -> [0-9] ]], 53 ^
51 [['p' =>]], 54]])
52 [['p' => 'q']], 55
53 [[()]], 56testerror([['p' /]], [[
54 -- 31-35 57L1:C6: expected a pattern after '/' or the label(s)
55 [[($$$)]], 58'p' /
56 [[('p' ('q' / 'r')]], 59 ^
57 [[% s]], 60]])
58 [[% {1}]], 61
59 [[{: *** :}]], 62testerror([['p' / / 'q']], [[
60 -- 36-40 63L1:C6: expected a pattern after '/' or the label(s)
61 [[{:group: *** :}]], 64'p' / / 'q'
62 [[{: group: 'p' :}]], 65 ^
63 [[S <- {: 'p' T <- 'q']], 66]])
64 [['<' {:tag: [a-z]+ :} '>' '<' = '>']], 67
65 [['<' {:tag: [a-z]+ :} '>' '<' = tag '>']], 68testerror([[&]], [[
66 -- 41-45 69L1:C2: expected a pattern after '&'
67 [[{~~}]], 70&
68 [[{ {~ } ~}]], 71 ^
69 [[{~ ^_^ ~}]], 72]])
70 [['p' {~ ('q' 'r') / 's']], 73
71 [[{0}]], 74testerror([[& / 'p']], [[
72 -- 46-50 75L1:C2: expected a pattern after '&'
73 [[{ :'p': }]], 76& / 'p'
74 [[{ 'p' ]], 77 ^
75 [[<>]], 78]])
76 [[<123>]], 79
77 [[< hello >]], 80testerror([['p' &]], [[
78 -- 51-55 81L1:C6: expected a pattern after '&'
79 [[<<S>>]], 82'p' &
80 [[<patt]], 83 ^
81 [[<insert your name here>]], 84]])
82 [[S <-]], 85
83 [[S <- 'p' T <-]], 86testerror([['p' / & / 'q']], [[
84 -- 55-60 87L1:C8: expected a pattern after '&'
85 [[[]], 88'p' / & / 'q'
86 [[[^]], 89 ^
87 [[[] ]], 90]])
88 [[[^] ]], 91
89 [[[_-___-_|]], 92testerror([[&&]], [[
90 -- 60-65 93L1:C3: expected a pattern after '&'
91 [['p' /{} 'q']], 94&&
92 [[%{ 'label' }]], 95 ^
93 [['p' /{1,2,3,} 'q']], 96]])
94 [[%{ a,,b,,c }]], 97
95 [['{' %{ a, b '}']], 98testerror([[!&]], [[
96 -- 65-70 99L1:C3: expected a pattern after '&'
97 [[Q <- "To be or not to be...]], 100!&
98 [['That is the question...]], 101 ^
99 [[{||}]], 102]])
100 [[{|@|}]], 103
101 [['p' {| 'q' / 'r' }]], 104testerror([[!]], [[
102 -- 71-75 105L1:C2: expected a pattern after '!'
103 [['a'/{1}'b'/'c']], -- should not fail anymore 106!
104 [[x <- {:x:}]], 107 ^
105 [[&'p'/&/!/'p'^'q']], 108]])
106 [[ 109
107 A <- 'a' (B 'b' 110testerror([[! / 'p']], [[
108 B <- 'x' / ! 111L1:C2: expected a pattern after '!'
109 C <- 'c' 112! / 'p'
110 ]], 113 ^
111 [[ 114]])
112 A <- %nosuch %def 115
113 A <- 'A again' 116testerror([['p' !]], [[
114 A <- 'and again' 117L1:C6: expected a pattern after '!'
115 ]], 118'p' !
116 -- 76 - 80 119 ^
117 [[names not in grammar]], 120]])
118 [[ 121
119 A <- %nosuch %def 122testerror([['p' / ! / 'q']], [[
120 A <- 'A again' 123L1:C8: expected a pattern after '!'
121 A <- 'and again' 124'p' / ! / 'q'
122 ]], 125 ^
123 [[ A <- %nosuch ('error' ]], 126]])
124 [[A <- Unknown Rules]], 127
125 [['a' / &@ ('c' / 'd')]], 128testerror([[!!]], [[
126 -- 81 - 85 129L1:C3: expected a pattern after '!'
127 [['x' / & / 'y']], 130!!
128 [[&/'p'/!/'q']], 131 ^
129 [['p'//'q']], 132]])
130 [[ 133
131 S <- 'forgot to close / T 134testerror([[&!]], [[
132 T <- 'T' & / 't' 135L1:C3: expected a pattern after '!'
133 ]], 136&!
134 [[ 137 ^
135 S <- [a-z / T 138]])
136 T <- 'x' / & / 'y' 139
137 ]], 140testerror([['p' ^ n]], [[
138 -- 86 - 88 141L1:C6: expected a number after '^', '+' or '-' (no space)
139 [[ 142'p' ^ n
140 S <- ('p' -- comment 143 ^
141 ]], 144]])
142 [[ 145
143 X <- ('p / Q (R 146testerror([['p'^+(+1)]], [[
144 / S)) 147L1:C5: expected a number after '^', '+' or '-' (no space)
145 Q <- 'q' 148'p'^+(+1)
146 R <- 'r' 149 ^
147 S <- 's' 150]])
148 ]], 151
149 [[ 152testerror([['p'^-/'q']], [[
150 A <- 'A' /{'lab'} B / ! 153L1:C5: expected a number after '^', '+' or '-' (no space)
151 154'p'^-/'q'
152 B <- %{1, 2 3} 'b' / '6' & / 'B' 155 ^
153 ]] 156]])
154} 157
155 158testerror([['p' -> {]], [[
156for i, patt in ipairs(patterns) do 159L1:C7: expected a string, number, '{}' or name after '->'
157 testerror(patt) 160'p' -> {
158end 161 ^
162]])
163
164testerror([['p' -> {'q'}]], [[
165L1:C7: expected a string, number, '{}' or name after '->'
166'p' -> {'q'}
167 ^
168]])
169
170testerror([['p' -> / 'q']], [[
171L1:C7: expected a string, number, '{}' or name after '->'
172'p' -> / 'q'
173 ^
174]])
175
176testerror([['p' -> [0-9] ]], [[
177L1:C7: expected a string, number, '{}' or name after '->'
178'p' -> [0-9]
179 ^
180]])
181
182testerror([['p' =>]], [[
183L1:C7: expected the name of a rule after '=>'
184'p' =>
185 ^
186]])
187
188testerror([['p' => 'q']], [[
189L1:C7: expected the name of a rule after '=>'
190'p' => 'q'
191 ^
192]])
193
194testerror([[()]], [[
195L1:C2: expected a pattern after '('
196()
197 ^
198]])
199
200testerror([[($$$)]], [[
201L1:C2: expected a pattern after '('
202($$$)
203 ^
204]])
205
206testerror([[('p' ('q' / 'r')]], [[
207L1:C17: missing closing ')'
208('p' ('q' / 'r')
209 ^
210]])
211
212testerror([[% s]], [[
213L1:C2: expected a name or label after '%' (no space)
214% s
215 ^
216]])
217
218testerror([[% {1}]], [[
219L1:C2: expected a name or label after '%' (no space)
220% {1}
221 ^
222]])
223
224testerror([[{: *** :}]], [[
225L1:C3: expected a pattern after ':'
226{: *** :}
227 ^
228]])
229
230testerror([[{:group: *** :}]], [[
231L1:C9: expected a pattern after ':'
232{:group: *** :}
233 ^
234]])
235
236testerror([[{: group: 'p' :}]], [[
237L1:C9: missing closing ':}'
238{: group: 'p' :}
239 ^
240L1:C9: unexpected characters after the pattern
241{: group: 'p' :}
242 ^
243]])
244
245testerror([[S <- {: 'p' T <- 'q']], [[
246L1:C12: missing closing ':}'
247S <- {: 'p' T <- 'q'
248 ^
249]])
250
251testerror([['<' {:tag: [a-z]+ :} '>' '<' = '>']], [[
252L1:C31: expected the name of a rule after '=' (no space)
253'<' {:tag: [a-z]+ :} '>' '<' = '>'
254 ^
255]])
256
257testerror([['<' {:tag: [a-z]+ :} '>' '<' = tag '>']], [[
258L1:C31: expected the name of a rule after '=' (no space)
259'<' {:tag: [a-z]+ :} '>' '<' = tag '>'
260 ^
261]])
262
263testerror([[{~~}]], [[
264L1:C3: expected a pattern after '{~'
265{~~}
266 ^
267]])
268
269testerror([[{ {~ } ~}]], [[
270L1:C5: expected a pattern after '{~'
271{ {~ } ~}
272 ^
273L1:C10: missing closing '}'
274{ {~ } ~}
275 ^
276]])
277
278testerror([[{~ ^_^ ~}]], [[
279L1:C3: expected a pattern after '{~'
280{~ ^_^ ~}
281 ^
282]])
283
284testerror([['p' {~ ('q' 'r') / 's']], [[
285L1:C23: missing closing '~}'
286'p' {~ ('q' 'r') / 's'
287 ^
288]])
159 289
160print() 290testerror([[{0}]], [[
161print("Tests passed: " .. npass .. "/" .. ntests) 291L1:C2: expected a pattern or closing '}' after '{'
292{0}
293 ^
294]])
295
296testerror([[{ :'p': }]], [[
297L1:C2: expected a pattern or closing '}' after '{'
298{ :'p': }
299 ^
300]])
301
302testerror([[{ 'p' ]], [[
303L1:C6: missing closing '}'
304{ 'p'
305 ^
306]])
307
308testerror([[<>]], [[
309L1:C2: expected the name of a rule after '<' (no space)
310<>
311 ^
312]])
313
314testerror([[<123>]], [[
315L1:C2: expected the name of a rule after '<' (no space)
316<123>
317 ^
318]])
319
320testerror([[< hello >]], [[
321L1:C2: expected the name of a rule after '<' (no space)
322< hello >
323 ^
324]])
325
326testerror([[<<S>>]], [[
327L1:C2: expected the name of a rule after '<' (no space)
328<<S>>
329 ^
330]])
331
332testerror([[<patt]], [[
333L1:C6: missing closing '>'
334<patt
335 ^
336]])
337
338testerror([[<insert your name here>]], [[
339L1:C8: missing closing '>'
340<insert your name here>
341 ^
342]])
343
344testerror([[S <-]], [[
345L1:C5: expected a pattern after '<-'
346S <-
347 ^
348]])
349
350testerror([[S <- 'p' T <-]], [[
351L1:C14: expected a pattern after '<-'
352S <- 'p' T <-
353 ^
354]])
355
356testerror([[[]], [[
357L1:C1: missing closing ']'
358[
359^
360]])
361
362testerror([[[^]], [[
363L1:C1: missing closing ']'
364[^
365^
366]])
367
368testerror([[[] ]], [[
369L1:C1: missing closing ']'
370[]
371^
372]])
373
374-- testerror([[[^] ]], [[
375-- L1:C1: missing closing ']'
376-- [^]
377-- ^
378-- ]])
379
380testerror([[[_-___-_|]], [[
381L1:C1: missing closing ']'
382[_-___-_|
383^
384]])
385
386testerror([['p' /{} 'q']], [[
387L1:C7: expected at least one label after '{'
388'p' /{} 'q'
389 ^
390]])
391
392testerror([[%{ 'label' }]], [[
393L1:C3: expected at least one label after '{'
394%{ 'label' }
395 ^
396]])
397
398testerror([['p' /{1,2,3,} 'q']], [[
399L1:C13: expected a label after the comma
400'p' /{1,2,3,} 'q'
401 ^
402]])
403
404testerror([[%{ a,,b,,c }]], [[
405L1:C6: expected a label after the comma
406%{ a,,b,,c }
407 ^
408]])
409
410testerror([['{' %{ a, b '}']], [[
411L1:C12: missing closing '}'
412'{' %{ a, b '}'
413 ^
414]])
415
416testerror([[Q <- "To be or not to be...]], [[
417L1:C6: missing terminating double quote
418Q <- "To be or not to be...
419 ^
420]])
421
422testerror([['That is the question...]], [[
423L1:C1: missing terminating single quote
424'That is the question...
425^
426]])
427
428testerror([[{||}]], [[
429L1:C3: expected a pattern after '{|'
430{||}
431 ^
432]])
433
434testerror([[{|@|}]], [[
435L1:C3: expected a pattern after '{|'
436{|@|}
437 ^
438]])
439
440testerror([['p' {| 'q' / 'r' }]], [[
441L1:C17: missing closing '|}'
442'p' {| 'q' / 'r' }
443 ^
444L1:C18: unexpected characters after the pattern
445'p' {| 'q' / 'r' }
446 ^
447]])
448
449testerror([[x <- {:x:}]], [[
450L1:C10: expected a pattern after ':'
451x <- {:x:}
452 ^
453]])
454
455testerror([[&'p'/&/!/'p'^'q']], [[
456L1:C7: expected a pattern after '&'
457&'p'/&/!/'p'^'q'
458 ^
459L1:C9: expected a pattern after '!'
460&'p'/&/!/'p'^'q'
461 ^
462L1:C14: expected a number after '^', '+' or '-' (no space)
463&'p'/&/!/'p'^'q'
464 ^
465]])
466
467testerror([[
468 A <- 'a' (B 'b'
469 B <- 'x' / !
470 C <- 'c'
471]],[[
472L1:C18: missing closing ')'
473 A <- 'a' (B 'b'
474 ^
475L2:C15: expected a pattern after '!'
476 B <- 'x' / !
477 ^
478]])
479
480testerror([[
481 A <- %nosuch %def
482 A <- 'A again'
483 A <- 'and again'
484]],[[
485name 'nosuch' undefined
486name 'def' undefined
487'A' already defined as a rule
488'A' already defined as a rule
489]])
490
491testerror([[names not in grammar]], [[
492rule 'names' used outside a grammar
493rule 'not' used outside a grammar
494rule 'in' used outside a grammar
495rule 'grammar' used outside a grammar
496]])
497
498testerror([[
499 A <- %nosuch %def
500 A <- 'A again'
501 A <- 'and again'
502]],[[
503name 'nosuch' undefined
504name 'def' undefined
505'A' already defined as a rule
506'A' already defined as a rule
507]])
508
509testerror([[ A <- %nosuch ('error' ]], [[
510L1:C23: missing closing ')'
511 A <- %nosuch ('error'
512 ^
513name 'nosuch' undefined
514]])
515
516-- testerror([[A <- Unknown Rules]], [[]])
517
518testerror([['a' / &@ ('c' / 'd')]], [[
519L1:C8: expected a pattern after '&'
520'a' / &@ ('c' / 'd')
521 ^
522]])
523
524testerror([['x' / & / 'y']], [[
525L1:C8: expected a pattern after '&'
526'x' / & / 'y'
527 ^
528]])
529
530testerror([[&/'p'/!/'q']], [[
531L1:C2: expected a pattern after '&'
532&/'p'/!/'q'
533 ^
534L1:C8: expected a pattern after '!'
535&/'p'/!/'q'
536 ^
537]])
538
539testerror([['p'//'q']], [[
540L1:C5: expected a pattern after '/' or the label(s)
541'p'//'q'
542 ^
543]])
544
545testerror([[
546 S <- 'forgot to close / T
547 T <- 'T' & / 't'
548]],[[
549L1:C8: missing terminating single quote
550 S <- 'forgot to close / T
551 ^
552L2:C13: expected a pattern after '&'
553 T <- 'T' & / 't'
554 ^
555]])
556
557testerror([[
558 S <- [a-z / T
559 T <- 'x' / & / 'y'
560]],[[
561L1:C8: missing closing ']'
562 S <- [a-z / T
563 ^
564L2:C15: expected a pattern after '&'
565 T <- 'x' / & / 'y'
566 ^
567]])
568
569testerror([[
570 S <- ('p' -- comment
571]],[[
572L1:C12: missing closing ')'
573 S <- ('p' -- comment
574 ^
575]])
576
577testerror([[
578 X <- ('p / Q (R
579 / S))
580 Q <- 'q'
581 R <- 'r'
582 S <- 's'
583]],[[
584L1:C9: missing terminating single quote
585 X <- ('p / Q (R
586 ^
587L2:C9: unexpected characters after the pattern
588 / S))
589 ^
590]])
591
592testerror([[
593 A <- 'A' /{'lab'} B / !
594
595 B <- %{1, 2 3} 'b' / '6' & / 'B'
596]],[[
597L1:C14: expected at least one label after '{'
598 A <- 'A' /{'lab'} B / !
599 ^
600L1:C26: expected a pattern after '!'
601 A <- 'A' /{'lab'} B / !
602 ^
603L3:C15: missing closing '}'
604 B <- %{1, 2 3} 'b' / '6' & / 'B'
605 ^
606]])
607
608
609print 'OK'
610 \ No newline at end of file