A Lua PEG library extension that adds labeled failures for error handling and recovery in parsing expression grammars.
LPegLabel is a Lua library that extends LPeg (Parsing Expression Grammars) by adding support for labeled failures. It allows parsers to throw custom error labels, which can be caught by recovery rules, enabling precise error reporting and recovery. This solves the problem of distinguishing between ordinary parsing failures and meaningful errors in PEG-based parsers.
Lua developers building parsers, compilers, or interpreters who need robust error handling and recovery mechanisms. It's particularly useful for those implementing domain-specific languages or structured data parsers where clear error messages are critical.
Developers choose LPegLabel because it integrates seamlessly with LPeg, adding error handling without breaking existing grammars. Its labeled failures and recovery system provide more control and better diagnostics than standard PEGs, making it a practical choice for real-world parsing tasks.
An extension of LPeg that supports labeled failures
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows throwing custom labels (strings or integers) to distinguish specific errors from ordinary failures, enabling precise error identification as shown in the README examples like m.T'ErrId'.
Supports recovery rules that match when a label is thrown, letting parsers resume regular matching after handling errors, demonstrated in the 'Error Recovery' example with rule *Err*.
Automatically reports the farthest input position for ordinary failures, improving debugging by providing context on where parsing went wrong, as illustrated in the 'Reporting the farthest failure' example.
Offers concise syntax like %{l} and p^l through the relabel module, simplifying error handling patterns and making grammars more readable, as seen in the *relabel* syntax example.
Error recovery requires defining and coordinating multiple recovery rules, which can lead to intricate grammar structures and increased maintenance burden, evident in the lengthy examples with auxiliary functions.
The README caveat warns that grammars with many rules may hit MAXRULES limits, necessitating changes to lpltypes.h in the C source code—an invasive step that limits portability and ease of use.
Assumes deep familiarity with LPeg and PEG concepts, and the labeled failure model adds another layer of complexity, making it challenging for developers new to parsing or error handling techniques.