diff options
author | Undecidable Robot <undecidabot@gmail.com> | 2016-05-23 07:57:55 +0800 |
---|---|---|
committer | Undecidable Robot <undecidabot@gmail.com> | 2016-05-23 07:57:55 +0800 |
commit | bd075f80398f4a21c47f8737922f21c4a4024f9b (patch) | |
tree | cb7318bcaad3780d9d5819116cfa4c0b757db719 | |
parent | dc19cc915c712137ad631c027ca6376d535df30a (diff) | |
download | lpeglabel-bd075f80398f4a21c47f8737922f21c4a4024f9b.tar.gz lpeglabel-bd075f80398f4a21c47f8737922f21c4a4024f9b.tar.bz2 lpeglabel-bd075f80398f4a21c47f8737922f21c4a4024f9b.zip |
Preventing the skipping of whitespace in error reports and cleaning code formatting
-rw-r--r-- | relabel.lua | 106 | ||||
-rw-r--r-- | testerrors.lua | 4 |
2 files changed, 63 insertions, 47 deletions
diff --git a/relabel.lua b/relabel.lua index aaed25c..95129db 100644 --- a/relabel.lua +++ b/relabel.lua | |||
@@ -187,8 +187,8 @@ local Def = name * m.Carg(1) | |||
187 | 187 | ||
188 | local num = m.C(m.R"09"^1) * S / tonumber | 188 | local num = m.C(m.R"09"^1) * S / tonumber |
189 | 189 | ||
190 | local String = "'" * m.C((any - "'" - m.P"\n")^0) * expect("'", "MisTerm1") + | 190 | local String = "'" * m.C((any - "'" - m.P"\n")^0) * expect("'", "MisTerm1") |
191 | '"' * m.C((any - '"' - m.P"\n")^0) * expect('"', "MisTerm2") | 191 | + '"' * m.C((any - '"' - m.P"\n")^0) * expect('"', "MisTerm2") |
192 | 192 | ||
193 | 193 | ||
194 | local defined = "%" * Def / function (c,Defs) | 194 | local defined = "%" * Def / function (c,Defs) |
@@ -207,8 +207,8 @@ local item = defined + Range + m.C(any - m.P"\n") | |||
207 | local Class = | 207 | local Class = |
208 | "[" | 208 | "[" |
209 | * (m.C(m.P"^"^-1)) -- optional complement symbol | 209 | * (m.C(m.P"^"^-1)) -- optional complement symbol |
210 | * m.Cf(expect(item, "ExpItem") * (item - "]")^0, mt.__add) / | 210 | * m.Cf(expect(item, "ExpItem") * (item - "]")^0, mt.__add) |
211 | function (c, p) return c == "^" and any - p or p end | 211 | / function (c, p) return c == "^" and any - p or p end |
212 | * expect("]", "MisClose8") | 212 | * expect("]", "MisClose8") |
213 | 213 | ||
214 | local function adddef (t, k, exp) | 214 | local function adddef (t, k, exp) |
@@ -264,58 +264,70 @@ local labelset2 = labify { | |||
264 | 264 | ||
265 | local exp = m.P{ "Exp", | 265 | local exp = m.P{ "Exp", |
266 | Exp = S * ( m.V"Grammar" | 266 | Exp = S * ( m.V"Grammar" |
267 | + (m.V"SeqLC" * ("/" * (m.Ct(m.V"Labels") + m.Cc(nil)) * S | 267 | + (m.V"SeqLC" * (S * "/" * (m.Ct(m.V"Labels") + m.Cc(nil)) |
268 | * m.Lc(expect(m.V"SeqLC", "ExpPatt1"), m.V"SkipToSlash", labels["ExpPatt1"]))^0) / labchoice ); | 268 | * m.Lc(expect(S * m.V"SeqLC", "ExpPatt1"), |
269 | Labels = m.P"{" * S * expect(m.V"Label", "ExpLab1") * (S * "," * S | 269 | m.V"SkipToSlash", labels["ExpPatt1"]) |
270 | * expect(m.V"Label", "ExpLab2"))^0 * S * expect("}", "MisClose7"); | 270 | )^0 |
271 | ) / labchoice); | ||
272 | Labels = m.P"{" * expect(S * m.V"Label", "ExpLab1") | ||
273 | * (S * "," * expect(S * m.V"Label", "ExpLab2"))^0 | ||
274 | * expect(S * "}", "MisClose7"); | ||
271 | SkipToSlash = (-m.P"/" * m.V"Stuff")^0 * m.Cc(dummy); | 275 | SkipToSlash = (-m.P"/" * m.V"Stuff")^0 * m.Cc(dummy); |
272 | Stuff = m.V"GroupedStuff" + any; | 276 | Stuff = m.V"Group" + any; |
273 | GroupedStuff = "(" * (-m.P")" * m.V"Stuff")^0 * ")" | 277 | Group = "(" * (-m.P")" * m.V"Stuff")^0 * ")" |
274 | + "{" * (-m.P"}" * m.V"Stuff")^0 * "}"; | 278 | + "{" * (-m.P"}" * m.V"Stuff")^0 * "}"; |
275 | SeqLC = m.Lc(m.V"Seq", m.V"SkipToSlash", unpack(labelset1)); | 279 | SeqLC = m.Lc(m.V"Seq", m.V"SkipToSlash", unpack(labelset1)); |
276 | Seq = m.Cf(m.Cc(m.P"") * m.V"Prefix"^1 , mt.__mul); | 280 | Seq = m.Cf(m.Cc(m.P"") * m.V"Prefix" * (S * m.V"Prefix")^0, mt.__mul); |
277 | Prefix = "&" * S * expect(m.V"Prefix", "ExpPatt2") / mt.__len | 281 | Prefix = "&" * expect(S * m.V"Prefix", "ExpPatt2") / mt.__len |
278 | + "!" * S * expect(m.V"Prefix", "ExpPatt3") / mt.__unm | 282 | + "!" * expect(S * m.V"Prefix", "ExpPatt3") / mt.__unm |
279 | + m.V"Suffix"; | 283 | + m.V"Suffix"; |
280 | Suffix = m.Cf(m.V"PrimaryLC" * S * | 284 | Suffix = m.Cf(m.V"PrimaryLC" * |
281 | ( ( m.P"+" * m.Cc(1, mt.__pow) | 285 | ( S * ( m.P"+" * m.Cc(1, mt.__pow) |
282 | + m.P"*" * m.Cc(0, mt.__pow) | 286 | + m.P"*" * m.Cc(0, mt.__pow) |
283 | + m.P"?" * m.Cc(-1, mt.__pow) | 287 | + m.P"?" * m.Cc(-1, mt.__pow) |
284 | + "^" * expect( m.Cg(num * m.Cc(mult)) | 288 | + "^" * expect( m.Cg(num * m.Cc(mult)) |
285 | + m.Cg(m.C(m.S"+-" * m.R"09"^1) * m.Cc(mt.__pow)), | 289 | + m.Cg(m.C(m.S"+-" * m.R"09"^1) * m.Cc(mt.__pow) |
286 | "ExpNum" | 290 | ), |
287 | ) | 291 | "ExpNum") |
288 | + "->" * S * expect( m.Cg((String + num) * m.Cc(mt.__div)) | 292 | + "->" * expect(S * ( m.Cg((String + num) * m.Cc(mt.__div)) |
289 | + m.P"{}" * m.Cc(nil, m.Ct) | 293 | + m.P"{}" * m.Cc(nil, m.Ct) |
290 | + m.Cg(Def / getdef * m.Cc(mt.__div)), | 294 | + m.Cg(Def / getdef * m.Cc(mt.__div)) |
291 | "ExpCap" | 295 | ), |
292 | ) | 296 | "ExpCap") |
293 | + "=>" * S * expect(m.Cg(Def / getdef * m.Cc(m.Cmt)), "ExpName1") | 297 | + "=>" * expect(S * m.Cg(Def / getdef * m.Cc(m.Cmt)), |
294 | ) * S | 298 | "ExpName1") |
299 | ) | ||
295 | )^0, function (a,b,f) return f(a,b) end ); | 300 | )^0, function (a,b,f) return f(a,b) end ); |
296 | PrimaryLC = m.Lc(m.V"Primary", ignore, unpack(labelset2)); | 301 | PrimaryLC = m.Lc(m.V"Primary", ignore, unpack(labelset2)); |
297 | Primary = "(" * expect(m.V"Exp", "ExpPatt4") * expect(")", "MisClose1") | 302 | Primary = "(" * expect(m.V"Exp", "ExpPatt4") * expect(S * ")", "MisClose1") |
298 | + String / mm.P | 303 | + String / mm.P |
299 | + Class | 304 | + Class |
300 | + defined | 305 | + defined |
301 | + "%" * expect(m.V"Labels", "ExpNameOrLab") / mm.T | 306 | + "%" * expect(m.V"Labels", "ExpNameOrLab") / mm.T |
302 | + "{:" * (name * ":" + m.Cc(nil)) * expect(m.V"Exp", "ExpPatt5") * expect(":}", "MisClose2") | 307 | + "{:" * (name * ":" + m.Cc(nil)) * expect(m.V"Exp", "ExpPatt5") |
303 | / function (n, p) return mm.Cg(p, n) end | 308 | * expect(S * ":}", "MisClose2") |
304 | + "=" * expect(name, "ExpName2") / function (n) return mm.Cmt(mm.Cb(n), equalcap) end | 309 | / function (n, p) return mm.Cg(p, n) end |
305 | + m.P"{}" / mm.Cp | 310 | + "=" * expect(name, "ExpName2") |
306 | + "{~" * expect(m.V"Exp", "ExpPatt6") * expect("~}", "MisClose3") / mm.Cs | 311 | / function (n) return mm.Cmt(mm.Cb(n), equalcap) end |
307 | + "{|" * expect(m.V"Exp", "ExpPatt7") * expect("|}", "MisClose4") / mm.Ct | 312 | + m.P"{}" / mm.Cp |
308 | + "{" * expect(m.V"Exp", "ExpPattOrClose") * expect("}", "MisClose5") / mm.C | 313 | + "{~" * expect(m.V"Exp", "ExpPatt6") |
309 | + m.P"." * m.Cc(any) | 314 | * expect(S * "~}", "MisClose3") / mm.Cs |
310 | + (name * -arrow + "<" * expect(name, "ExpName3") * expect(">", "MisClose6")) * m.Cb("G") / NT; | 315 | + "{|" * expect(m.V"Exp", "ExpPatt7") |
316 | * expect(S * "|}", "MisClose4") / mm.Ct | ||
317 | + "{" * expect(m.V"Exp", "ExpPattOrClose") | ||
318 | * expect(S * "}", "MisClose5") / mm.C | ||
319 | + m.P"." * m.Cc(any) | ||
320 | + (name * -arrow + "<" * expect(name, "ExpName3") | ||
321 | * expect(">", "MisClose6")) * m.Cb("G") / NT; | ||
311 | Label = num + name / function (f) return tlabels[f] end; | 322 | Label = num + name / function (f) return tlabels[f] end; |
312 | Definition = name * arrow * expect(m.V"Exp", "ExpPatt8"); | 323 | Definition = name * arrow * expect(m.V"Exp", "ExpPatt8"); |
313 | Grammar = m.Cg(m.Cc(true), "G") * | 324 | Grammar = m.Cg(m.Cc(true), "G") |
314 | m.Cf(m.V"Definition" / firstdef * m.Cg(m.V"Definition")^0, | 325 | * m.Cf(m.V"Definition" / firstdef * (S * m.Cg(m.V"Definition"))^0, |
315 | adddef) / mm.P | 326 | adddef) / mm.P; |
316 | } | 327 | } |
317 | 328 | ||
318 | local pattern = S * m.Cg(m.Cc(false), "G") * expect(exp, "NoPatt") / mm.P * expect(-any, "ExtraChars") | 329 | local pattern = S * m.Cg(m.Cc(false), "G") * expect(exp, "NoPatt") / mm.P |
330 | * S * expect(-any, "ExtraChars") | ||
319 | 331 | ||
320 | local function lineno (s, i) | 332 | local function lineno (s, i) |
321 | if i == 1 then return 1, 1 end | 333 | if i == 1 then return 1, 1 end |
diff --git a/testerrors.lua b/testerrors.lua index b82c591..30bbbe2 100644 --- a/testerrors.lua +++ b/testerrors.lua | |||
@@ -134,6 +134,10 @@ local patterns = { | |||
134 | [[ | 134 | [[ |
135 | S <- [a-z / T | 135 | S <- [a-z / T |
136 | T <- 'x' / & / 'y' | 136 | T <- 'x' / & / 'y' |
137 | ]], | ||
138 | -- 86 | ||
139 | [[ | ||
140 | S <- ('p' -- comment | ||
137 | ]] | 141 | ]] |
138 | } | 142 | } |
139 | 143 | ||