What is the idiomic way to create error messages in LPEG ?
To be specific I would like to create error messages for incomplete bracket completion.
Example :
[ 1 2 3 -- ERROR ! MISSING ] AT LINE 20
( 1 2 3 -- ERROR ! MISSING ) AT LINE 35
{ 1 2 3 -- ERROR ! MISSING } AT LINE 12
1 2 3 ] -- ERROR ! EXTRA ] AT LINE 42
[ ( 1 2 3 ] -- ERROR ! MISSING ) AT LINE 71
I have figured out that I need to use lpeg.Carg to pass a table to log line number but how can a pattern fail in a certain way as to let its error be know ?
local show = function(...)
{tab,cap} = arg
print (cap)
end
local inner = C(1 - P(']'))^0
local patt = P('[') * inner * P(']')
local test = Cmt((patt * (Carg(1))), show)
local out = test:match('[hello', 1, { })
return log(out) -- nil ??
The problem is the function show
does not run if the pattern fails.
It also doen't not run if I use Cmt
, but I think I am missing the larger picture.