blob: fc213bcd2e71fdfb3642c9bc0b85a89c6e566738 (
plain)
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
|
local re = require 'relabel'
local g = re.compile[[
S <- Id List
List <- !. / (',' / %{2}) Id List
Id <- [a-z] / %{1}
]]
function mymatch (g, s)
local r, e, sfail = g:match(s)
if not r then
if e == 1 then
return r, "Error: expecting an identifier before '" .. sfail .. "'"
elseif e == 2 then
return r, "Error: expecting ',' before '" .. sfail .. "'"
else
return r, "Error"
end
end
return r
end
print(mymatch(g, "a,b"))
print(mymatch(g, "a b"))
print(mymatch(g, ", b"))
|