-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.lua
More file actions
40 lines (33 loc) · 821 Bytes
/
error.lua
File metadata and controls
40 lines (33 loc) · 821 Bytes
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
local Error = {
__tostring = function(s)
return s.path .. ":" .. s.line .. " " .. s.type .. ": " .. s.msg
end
}
Error.__index = Error
function Error.new(type, msg, line, path)
local t = {
type = type,
msg = msg,
line = line or "-",
path = path or "source",
}
return setmetatable(t, Error)
end
local E = {}
function E.Lexical(msg, line, path)
local e = Error.new("LexicalError", msg, line, path)
error(e, 0)
end
function E.Syntax(msg, line, path)
local e = Error.new("SyntaxError", msg, line, path)
error(e, 0)
end
function E.Type(msg, line, path)
local e = Error.new("TypeError", msg, line, path)
error(e, 0)
end
function E.Name(msg, line, path)
local e = Error.new("NameError", msg, line, path)
error(e, 0)
end
return E