glados-0.1.0.0
Stabilitystable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Common.Error

Description

This module provides tools to transform technical Megaparsec errors into human-readable, colored error messages. It helps standardize error reporting across the entire application (Parsing, Semantics, Imports).

Synopsis

Documentation

formatParseError :: ParseErrorBundle Text Void -> String Source #

Main entry point to format a Megaparsec error bundle.

@args - bundle: The full error bundle returned by parse.

@details Extracts the first error, calculates position, and formats the message. Refactored to meet coding style (short function, short lines).

formatError :: String -> String -> String Source #

Formats a generic error message with a colored tag.

@args - tag: The error category (e.g., "Semantic Error", "Import Error"). - msg: The error description.

@return A formatted string with the tag in red ANSI color.

formatFancyError :: Set (ErrorFancy Void) -> String Source #

Format FancyError messages (generated by fail).

@details Iterates over the set of fancy errors and extracts the text message if it exists (ErrorFail).

getExpected :: ParseError Text Void -> String Source #

Extracts the "expected" tokens from a ParseError.

@args - err: The Megaparsec error object.

@return A clean string listing expected tokens or "custom error".

getUnexpected :: ParseError Text Void -> String Source #

Extracts the "unexpected" token from a ParseError.

@args - err: The Megaparsec error object.

@return A string describing what was found instead (e.g., "end of input", ""foo"").