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
|
local re = require 'relabel'
local npass, ntests = 0, 0
function testerror(repatt)
ntests = ntests + 1
local ok, err = pcall(function () re.compile(repatt) end)
if ok then
print("FAIL", ntests)
else
npass = npass + 1
print("PASS", ntests, err)
end
end
local patterns = {
-- 1-5
[[~]],
[[???]],
[['p'~]],
[['p'?$?]],
[['p' /{1}]],
-- 6-10
[['p' /{1} /{2} 'q']],
[['p' /]],
[['p' / / 'q']],
[[&]],
[[& / 'p']],
-- 11-15
[['p' &]],
[['p' / & / 'q']],
[[&&]],
[[!&]],
[[!]],
-- 16-20
[[! / 'p']],
[['p' !]],
[['p' / ! / 'q']],
[[!!]],
[[&!]],
-- 21-25
[['p' ^ n]],
[['p'^+(+1)]],
[['p'^-/'q']],
[['p' -> {]],
[['p' -> {'q'}]],
-- 26-30
[['p' -> / 'q']],
[['p' -> [0-9] ]],
[['p' =>]],
[['p' => 'q']],
[[()]],
-- 31-35
[[($$$)]],
[[('p' ('q' / 'r')]],
[[% s]],
[[% {1}]],
[[{: *** :}]],
-- 36-40
[[{:group: *** :}]],
[[{: group: 'p' :}]],
[[S <- {: 'p' T <- 'q']],
[['<' {:tag: [a-z]+ :} '>' '<' = '>']],
[['<' {:tag: [a-z]+ :} '>' '<' = tag '>']],
-- 41-45
[[{~~}]],
[[{ {~ } ~}]],
[[{~ ^_^ ~}]],
[['p' {~ ('q' 'r') / 's']],
[[{0}]],
-- 46-50
[[{ :'p': }]],
[[{ 'p' ]],
[[<>]],
[[<123>]],
[[< hello >]],
-- 51-55
[[<<S>>]],
[[<patt]],
[[<insert your name here>]],
[[S <-]],
[[S <- 'p' T <-]],
-- 55-60
[[[]],
[[[^]],
[[[] ]],
[[[^] ]],
[[[_-___-_|]],
-- 60-65
[['p' /{} 'q']],
[[%{ 'label' }]],
[['p' /{1,2,3,} 'q']],
[[%{ a,,b,,c }]],
[['{' %{ a, b '}']],
-- 65-70
[[Q <- "To be or not to be...]],
[['That is the question...]],
[[{||}]],
[[{|@|}]],
[['p' {| 'q' / 'r' }]],
-- 71-75
[['a'/{1}'b'/'c']], -- should not fail anymore
[[x <- {:x:}]],
[[&'p'/&/!/'p'^'q']],
[[
A <- 'a' (B 'b'
B <- 'x' / !
C <- 'c'
]],
[[
A <- %nosuch %def
A <- 'A again'
A <- 'and again'
]],
-- 76 - 80
[[names not in grammar]],
[[
A <- %nosuch %def
A <- 'A again'
A <- 'and again'
]],
[[ A <- %nosuch ('error' ]],
[[A <- Unknown Rules]],
[['a' / &@ ('c' / 'd')]],
-- 81 - 85
[['x' / & / 'y']],
[[&/'p'/!/'q']],
[['p'//'q']],
[[
S <- 'forgot to close / T
T <- 'T' & / 't'
]],
[[
S <- [a-z / T
T <- 'x' / & / 'y'
]],
-- 86 - 88
[[
S <- ('p' -- comment
]],
[[
X <- ('p / Q (R
/ S))
Q <- 'q'
R <- 'r'
S <- 's'
]],
[[
A <- 'A' /{'lab'} B / !
B <- %{1, 2 3} 'b' / '6' & / 'B'
]]
}
for i, patt in ipairs(patterns) do
testerror(patt)
end
print()
print("Tests passed: " .. npass .. "/" .. ntests)
|