formatMessage

fun ParseException.formatMessage(maxLineLength: Int = 80): String

Formats a parse error into a user-friendly error message with context.

The formatted message includes:

  • Error line and column number

  • Expected parsers (if named parsers are available)

  • Actual character found (or EOF)

  • The source line where the error occurred (truncated to maxLineLength if needed)

  • A caret (^) indicating the error position

Return

A formatted error message with context

Parameters

exception

The parse exception to format

maxLineLength

Maximum length for the source line display (default 80)