Documentation Index
Fetch the complete documentation index at: https://mintlify.com/saiashirwad/parserator/llms.txt
Use this file to discover all available pages before exploring further.
Quickstart
Let’s build a parser for coordinate points like(10,20). You’ll learn the core concepts of Parserator through a hands-on example.
What we’ll build
By the end of this tutorial, you’ll have a parser that:- Parses coordinates in the format
(x,y) - Handles numbers with multiple digits
- Provides helpful error messages
- Has full TypeScript type inference
Parse a single digit
Start by importing the basic combinators and parsing a single digit:The
digit parser matches any single digit character (0-9) and returns it as a string.Parse multiple digits into a number
Use Here’s what’s happening:
many1 to parse one or more digits, then transform them into a number:many1(digit)parses one or more digits, returningstring[].map()transforms the array of digit strings into a single number- TypeScript infers the final type as
number
Use generator syntax to parse coordinates
Now combine parsers using generator syntax to parse the full coordinate format:The
parser function creates a parser from a generator. Each yield* runs a parser and extracts its value. The final return is the parser’s result.Notice how TypeScript automatically infers that
x and y are numbers, and the final result is { x: number, y: number }.Use .parse() for error handling
The The
parseOrThrow() method throws an exception on failure. Use .parse() for explicit error handling:.parse() method returns a ParserOutput with an Either type:Leftcontains the error bundleRightcontains the successful result
Add better error messages
Use Now errors tell you exactly what went wrong instead of just “parse failed”.
.expect() to provide context-specific error messages:Complete example
Here’s the full code from this tutorial:Key concepts you learned
- Basic parsers:
digit,char(),string()match simple patterns - Combinators:
many1()repeats a parser one or more times - Transformation:
.map()transforms parser results - Generator syntax:
parser(function* () { ... })composes parsers sequentially - Error handling:
.parse()vs.parseOrThrow() - Better errors:
.expect()adds context to error messages
What’s next?
You now know enough to build useful parsers! Here are some ideas to explore:Core concepts
Deep dive into parser combinators, generators, and error handling
API reference
Explore all available parsers and combinators
Error handling
Learn about commit, backtracking, and rich error messages
Examples
Study complete examples like JSON, INI, and language parsers