parsing

Parse structured input with lean4-parser combinators for Lean text processing.

3|Updated Dec 3, 2025
One-click install
npx skills add https://github.com/kim-em/AoC2025 --skill parsing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: parsing
Source: https://github.com/kim-em/AoC2025/tree/main/.claude/skills/parsing
Command: npx skills add https://github.com/kim-em/AoC2025 --skill parsing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill demonstrates how to use the lean4-parser library to parse structured input, reducing ad-hoc string handling and increasing correctness for AoC puzzles and general text processing tasks.

Core Features & Use Cases

  • SimpleParser usage: Leverage SimpleParser and parser combinators for robust parsing with helpful error messages.
  • Common Combinators: Use primitives like char, string, ASCII.parseInt, sepBy, first, and endOfInput to build clear parsers.
  • Use Case: Parse AoC puzzle inputs such as lines of numbers, coordinates, or key-value pairs into structured data.

Quick Start

Create a Small parser using lean4-parser to read a line like "1, -2, 3" into a list [1, -2, 3], and run it on your input.

Frequently Asked Questions about parsing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I parse structured input in Lean 4 without manual string splitting?

Use the lean4-parser library with SimpleParser and combinators like `char`, `string`, and `ASCII.parseInt` to build robust parsers. This approach eliminates ad-hoc string handling and provides helpful error messages for tasks like parsing numbers, coordinates, and key-value pairs.

What parser combinators does lean4-parser provide for common tasks?

lean4-parser includes primitives such as `ASCII.parseNat`, `ASCII.parseInt`, `sepBy`, `takeMany`, `dropMany`, `whitespace`, `eol`, `endOfInput`, and `optional`. These combinators compose to handle lines of numbers, coordinate lists, and structured data parsing efficiently.

Can I use lean4-parser for Advent of Code puzzle inputs?

Yes. lean4-parser is designed for AoC parsing tasks. Build parsers to read formatted inputs like "1, -2, 3" into structured data, avoiding fragile splitting and regex approaches while maintaining clarity and correctness.

How do I handle optional fields and repeated patterns when parsing?

Combine `optional` for conditional fields and `sepBy` or `takeMany` for repeated elements. These combinators let you express variable-length inputs and missing values cleanly without nested conditionals or loops.

What's the best way to validate parser output in Lean 4?

Use `endOfInput` to ensure the entire input is consumed and `test` to validate parser results. lean4-parser's error messages guide debugging, and type safety in Lean enforces constraints on parsed values.

Do I need prior parser experience to use lean4-parser?

No. Start with SimpleParser and basic combinators. The library abstracts parser complexity; you compose simple, readable functions to build parsers incrementally without deep combinator theory.