mirror of
https://github.com/schneiderfelipe/microparsec
synced 2026-01-14 20:01:40 +00:00
No description
Previous implementation was discarding the Result[T] for <*, which meant that writing ```nim many(digit) <* eof ``` did also match `8394 483` because the eof would fail but such result would be discarded. Instead what we want is to also try to parse the second result and if it fails then we return a failure, otherwise we return only the first correctly parsed result. |
||
|---|---|---|
| docs | ||
| src | ||
| tests | ||
| .gitignore | ||
| LICENSE | ||
| microparsec.nimble | ||
| README.md | ||
Microparsec ⭐
[WIP] Microparsec is a fast parser combinator library with excellent error messages.
import microparsec
let p = between(
ch('{'),
str("hello") >> many(space) >> str("world!"),
ch('}')
)
echo p.parse("{hello\n world?}")
Failed reading: satisfy
1:6:(13):
|
1 | world?}
| ^
unexpected '?'
expecting "world!"
Microparsec is a pure Nim adaptation of Parsec, the popular monadic parser combinator library for Haskell by Daan Leijen, Further inspiration was taken from Attoparsec and Megaparsec.
Installation
Microparsec supports Nim 1.2.6+ and can be installed using Nimble:
$ nimble install microparsec
Some references
- Leijen, Daan & Meijer, Erik. (2001). Parsec: Direct Style Monadic Parser Combinators For The Real World.
- Holden, Daniel. (2014). You could have invented Parser Combinators.
Inspiring projects
- Attoparsec (Haskell)
- Megaparsec (Haskell)
- Parsec (Haskell)