Lua.Parser.Recovery (Lua v1.0.0-rc.1)
View SourceError recovery strategies for the Lua parser.
Allows the parser to continue after encountering errors, collecting multiple errors in a single parse pass.
Summary
Functions
Checks if a token is a statement boundary (synchronization point).
Attempts to recover from a parse error by finding a synchronization point.
Attempts to recover from missing keyword error.
Recovers from an unclosed delimiter by finding the matching closing delimiter.
Skips tokens until we find a valid statement start.
Types
@type recovery_result() :: {:recovered, [token()], [Lua.Parser.Error.t()]} | {:failed, [Lua.Parser.Error.t()]}
@type token() :: Lua.Lexer.token()
Functions
Checks if a token is a statement boundary (synchronization point).
@spec recover_at_statement([token()], Lua.Parser.Error.t()) :: recovery_result()
Attempts to recover from a parse error by finding a synchronization point.
Synchronization points are tokens where we can safely resume parsing:
- Statement boundaries:
;,end,else,elseif,until - Block terminators:
},) - Start of new statements: keywords like
if,while,for,function,local
@spec recover_missing_keyword([token()], atom(), Lua.Parser.Error.t()) :: recovery_result()
Attempts to recover from missing keyword error.
@spec recover_unclosed_delimiter([token()], atom(), Lua.Parser.Error.t()) :: recovery_result()
Recovers from an unclosed delimiter by finding the matching closing delimiter.
Skips tokens until we find a valid statement start.