aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUndecidable Robot <undecidabot@gmail.com>2016-05-07 22:00:25 +0800
committerUndecidable Robot <undecidabot@gmail.com>2016-05-07 22:04:37 +0800
commit76170bacefad40b79a1f8a93294d2c96711a3b1e (patch)
tree6244fb3a0f3ec1a68c8a0bab567e620a5aa99407
parenta3e8fbe233e7b3ca7a4e72ec03a495da79450b17 (diff)
downloadlpeglabel-76170bacefad40b79a1f8a93294d2c96711a3b1e.tar.gz
lpeglabel-76170bacefad40b79a1f8a93294d2c96711a3b1e.tar.bz2
lpeglabel-76170bacefad40b79a1f8a93294d2c96711a3b1e.zip
Adding proper error messages
-rw-r--r--relabel.lua38
1 files changed, 37 insertions, 1 deletions
diff --git a/relabel.lua b/relabel.lua
index 3748da6..16c5473 100644
--- a/relabel.lua
+++ b/relabel.lua
@@ -230,12 +230,48 @@ local function lineno (s, i)
230 return 1 + num, r ~= 0 and r or 1 230 return 1 + num, r ~= 0 and r or 1
231end 231end
232 232
233local errorMessages = {
234 "No pattern found",
235 "Unexpected characters after the pattern",
236 "Expected a pattern after labels",
237 "Expected a pattern after `/`",
238 "Expected a pattern after `&`",
239 "Expected a pattern after `!`",
240 "Expected a valid number after `^`",
241 "Expected `}` right after `{`",
242 "Expected a string, number, `{}` or name after `->`",
243 "Expected a name after `=>`",
244 "Expected a pattern after `(`",
245 "Missing the closing `)` after pattern",
246 "Expected a name or labels right after `%` (without any space)",
247 "Expected a pattern after `{:` or `:`",
248 "Missing the closing `:}` after pattern",
249 "Expected a name after `=` (without any space)",
250 "Expected a pattern after `{~`",
251 "Missing the closing `~}` after pattern",
252 "Expected a pattern or closing `}` after `{`",
253 "Missing the closing `}` after pattern",
254 "Expected a name right after `<`",
255 "Missing the closing `>` after the name",
256 "Expected a pattern after `<-`",
257 "Expected at least one item after `[` or `^`",
258 "Missing the closing `]` after the items",
259 "Expected an item after the `-` (except `]`)",
260 "Expected at least one label after the `{`",
261 "Expected a label after the comma",
262 "Missing closing `}` after the labels",
263 "Missing closing double quote in string",
264 "Missing closing single quote in string",
265 "Expected a pattern after `{|`",
266 "Missing the closing `|}` after pattern",
267}
268
233local function compile (p, defs) 269local function compile (p, defs)
234 if mm.type(p) == "pattern" then return p end -- already compiled 270 if mm.type(p) == "pattern" then return p end -- already compiled
235 local cp, label, suffix = pattern:match(p, 1, defs) 271 local cp, label, suffix = pattern:match(p, 1, defs)
236 if not cp then 272 if not cp then
237 local line, col = lineno(p, p:len() - suffix:len()) 273 local line, col = lineno(p, p:len() - suffix:len())
238 error("incorrect pattern on line " .. line .. " col " .. col .. ": " .. label, 3) 274 error("Line" .. line .. ", Col " .. col .. ": " .. errorMessages[label], 3)
239 end 275 end
240 return cp 276 return cp
241end 277end