Skip to content

Instantly share code, notes, and snippets.

@rns
Created May 22, 2015 05:21
Show Gist options
  • Save rns/9b788e134d297ed83984 to your computer and use it in GitHub Desktop.
Save rns/9b788e134d297ed83984 to your computer and use it in GitHub Desktop.
locations in LPeg messages on errors in grammars
local lpeg = require 'lpeg'
equalcount = lpeg.P{
"S"; -- initial rule name
S = "a" * lpeg.V"B" + "b" * lpeg.V"A" + "",
A = "a" * lpeg.V"S" + "b" * lpeg.V"A" * lpeg.V"A",
-- , '1' added to produce error
B = "b", '1' * lpeg.V"S" + "a" * lpeg.V"B" * lpeg.V"B",
} * -1
lua: lpeg-locations.lua:3: rule 'B' is not a pattern
stack traceback:
[C]: in function 'P'
lpeg-locations.lua:3: in main chunk
[C]: ?
local lpeg = require 'lpeg'
equalcount = lpeg.P{
"S"; -- initial rule name
S = "a" * lpeg.V"B" + "b" * lpeg.V"A" + "",
-- ++++ added to produce error
A = "a" * lpeg.V"S++++" + "b" * lpeg.V"A" * lpeg.V"A",
B = "b" * lpeg.V"S" + "a" * lpeg.V"B" * lpeg.V"B",
} * -1
lua: lpeg-locations.lua:3: rule 'S++++' undefined in given grammar
stack traceback:
[C]: in function 'P'
lpeg-locations.lua:3: in main chunk
[C]: ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment