Lua.Parser.Error (Lua v1.0.0-rc.1)

View Source

Beautiful error reporting for the Lua parser.

Provides detailed error messages with:

  • Source code context with line numbers
  • Visual indicators pointing to the error location
  • Helpful suggestions for common mistakes
  • Multiple error reporting

Summary

Functions

Formats an error into a beautiful multi-line string with context.

Formats multiple errors together.

Creates an error for unclosed delimiter.

Creates an error for unexpected end of input.

Creates an error for unexpected token.

Types

error_type()

@type error_type() ::
  :unexpected_token
  | :unexpected_end
  | :expected_token
  | :unclosed_delimiter
  | :invalid_syntax
  | :lexer_error
  | :multiple_errors

position()

@type position() :: Lua.AST.Meta.position()

t()

@type t() :: %Lua.Parser.Error{
  message: String.t(),
  position: position() | nil,
  related: [t()],
  source_lines: [String.t()],
  suggestion: String.t() | nil,
  type: error_type()
}

Functions

expected_token(expected_type, expected_value, got_type, got_value, position)

@spec expected_token(atom(), term() | nil, atom(), term(), position()) :: t()

Creates an error for expected token.

format(error, source_code)

@spec format(t(), String.t()) :: String.t()

Formats an error into a beautiful multi-line string with context.

format_multiple(errors, source_code)

@spec format_multiple([t()], String.t()) :: String.t()

Formats multiple errors together.

new(type, message, position \\ nil, opts \\ [])

@spec new(error_type(), String.t(), position() | nil, keyword()) :: t()

Creates a new error.

unclosed_delimiter(delimiter, open_pos, close_pos \\ nil)

@spec unclosed_delimiter(atom(), position(), position() | nil) :: t()

Creates an error for unclosed delimiter.

unexpected_end(context, position \\ nil)

@spec unexpected_end(String.t(), position() | nil) :: t()

Creates an error for unexpected end of input.

unexpected_token(token_type, token_value, position, context)

@spec unexpected_token(atom(), term(), position(), String.t()) :: t()

Creates an error for unexpected token.