microparsec
microparsec copied to clipboard
Utilities for parsing numbers and string versus seq[char]
Implement the relevant parsers from Text.Megaparsec.Char.Lexer
.
By the way, the following does not work
import parseutils
import microparsec
let p = many1(digit).map(parseInt)
echo p.parse("1234") + 1 # should be 1235
/home/schneider/Dropbox/microparsec/examples/asdf.nim(3, 21) Error: type mismatch: got <Parser[seq[char]],
proc (s: string, number: var int, start: int): int{.noSideEffect, gcsafe, locks: 0.}>
but expected one of:
func map[S, T](parser: Parser[S]; f: S -> T): Parser[T]
first type mismatch at position: 2
required type for f: proc (i0: S): T{.closure.}
but expression 'parseInt' is of type: proc (s: string, number: var int, start: int): int{.noSideEffect,
gcsafe, locks: 0.}
expression: map(
liftA2(proc (x: T; xs: seq[T]): auto = result = x & xs, digit, many digit),
parseInt)
which is related to #6.