lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> In MoonScript's inspired, I'm trying to make a tiny compiler with
> lpeg, but I found a problem: when the subject is incorrect, or I write
> a wrong pattern, the match just return nil, not any other things, It
> makes debug program very difficult, So I had to ask, has any idea to
> implement a fallback function for the pattern match?
> the fallback function may get some information, e.g. failure position,
> expected terminal or other information, but I can't output error
> message such as "test.moon: 10: `ident' expected after `,'" if I only
> have failure position, How could I produce messages like this? maybe a
> function mark() to mark some terminal/nonterminal to makes they can be
> shown in message?

For some inspiration, you may have a look at how 're.lua' (part of LPeg
distribution) handles errors. Look for function 'patt_error'. (For
line information, just count the number of newlines until the current

-- Roberto