$ show mrkkrp/megaparsec
Megaparsec is an industrial-strength monadic parser combinator library for Haskell. It provides a feature-rich balance between speed, flexibility, and quality of parse errors. The library supports parsing String, ByteString, and Text (both strict and lazy) input streams, with sophisticated error reporting that includes source code position highlighting, custom error components, and bundled error messages. It includes utilities for whitespace and comment handling, indentation-sensitive grammars, and lexing of numbers and literals. The architecture is modular, with core parsing functionality in Text.Megaparsec and specialized modules for byte/char processing, error handling, and lexing.
The LLM identified 3 files worth highlighting for reuse:
Defines Pos (positive integer wrapper) and SourcePos (filename, line, column) types with smart constructors that prevent invalid positions. Completely isolated with no internal Megaparsec dependencies, making it reusable in any system requiring source position tracking. Demonstrates proper encapsulation and error handling through the InvalidPosException type.
Provides utilities for working with Unicode characters, including stringLength (accounting for wide characters), charLength, isWideChar, and isZeroWidthChar. Uses efficient range-based lookup via arrays to determine character properties. Completely isolated with no internal dependencies, solving a general text processing problem reusable in many contexts.
Implements a sophisticated error handling system with typed error components (ErrorItem, ErrorFancy), ParseError with TrivialError/FancyError constructors, and ParseErrorBundle for efficient multi-error reporting. Features pretty-printing with source code display, position markers, continuous highlighting for multi-character errors, and proper handling of tabs, zero-width, and wide Unicode characters. Shows exceptional skill in an area where many parser libraries struggle.