Class VisualErrorFormatter

java.lang.Object
org.ek9lang.compiler.common.VisualErrorFormatter

public final class VisualErrorFormatter extends Object
Formats compiler errors in a visual style similar to Rust/Elm compilers. Displays the source code line with underline markers pointing to the error location. Supports colors and Unicode symbols when terminal capabilities are detected.

Example output (with colors/symbols):

❌ error[E02010]: Property/Field duplicated
 ──▶ example.ek9:12:7
    │
 12 │   prop3 <- String()
    │   ^^^^^ property already exists in parent type
    │
    ├─ 💡 Did you mean: 'prop2'?
    └─ 🔗 See: https://ek9.io/errors.html#E02010
  • Method Details

    • format

      public static String format(String classification, String errorCode, String fileName, int lineNumber, int position, int tokenLength, String sourceLine, String errorMessage, String detailMessage)
      Format an error with visual source display.
      Parameters:
      classification - The error classification (Error, Warning, etc.)
      errorCode - The error code (e.g., "E02010")
      fileName - The source file name
      lineNumber - The 1-based line number
      position - The 0-based character position on the line
      tokenLength - The length of the offending token
      sourceLine - The actual source code line content
      errorMessage - The primary error message
      detailMessage - Additional detail message (can be null)
      Returns:
      The formatted visual error string
    • format

      public static String format(String classification, String errorCode, String fileName, int lineNumber, int position, int tokenLength, String sourceLine, String errorMessage, String detailMessage, MatchResults fuzzyResults)
      Format an error with visual source display and fuzzy match suggestions.
      Parameters:
      classification - The error classification (Error, Warning, etc.)
      errorCode - The error code (e.g., "E02010")
      fileName - The source file name
      lineNumber - The 1-based line number
      position - The 0-based character position on the line
      tokenLength - The length of the offending token
      sourceLine - The actual source code line content
      errorMessage - The primary error message
      detailMessage - Additional detail message (can be null)
      fuzzyResults - Fuzzy match suggestions (can be null)
      Returns:
      The formatted visual error string