| Parser Combinators(t3.at) | |
| 248 points by schindlabua 7 days ago | 88 comments | |
tl;dr: Parser combinators model parsers as functions of type `(input: string) => [T, string]`, returning a parsed value plus the remaining unconsumed input. Small primitive parsers (like `pInteger`, `pHello`, `pIgnoreWhitespace`) can be composed with higher-order combinators like `pSeq` and `pMap` to build complex parsers—for example, turning raw `ping` output into a structured object. The approach is essentially the inverse of a fold: where reduce collapses a list into a value, parsing unfolds a string into structured data. | |
HN Discussion:
| |