Lua.Parser.Recovery (Lua v1.0.0-rc.2)

View Source

Error 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

recovery_result()

@type recovery_result() ::
  {:recovered, [token()], [Lua.Parser.Error.t()]}
  | {:failed, [Lua.Parser.Error.t()]}

token()

@type token() :: Lua.Lexer.token()

Functions

is_statement_boundary?(token)

@spec is_statement_boundary?(token()) :: boolean()

Checks if a token is a statement boundary (synchronization point).

recover_at_statement(tokens, error)

@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

recover_missing_keyword(tokens, keyword, error)

@spec recover_missing_keyword([token()], atom(), Lua.Parser.Error.t()) ::
  recovery_result()

Attempts to recover from missing keyword error.

recover_unclosed_delimiter(tokens, delimiter_type, error)

@spec recover_unclosed_delimiter([token()], atom(), Lua.Parser.Error.t()) ::
  recovery_result()

Recovers from an unclosed delimiter by finding the matching closing delimiter.

skip_to_statement(tokens)

@spec skip_to_statement([token()]) :: [token()]

Skips tokens until we find a valid statement start.