Add digit helper

This commit is contained in:
Florian Schroedl
2022-08-26 16:30:47 +02:00
parent 018e28bc84
commit 80c911e41f

View File

@@ -94,6 +94,7 @@ proc ch*(expectedChar: char): parserFnT {.inline.} =
))
let anyCh* = ch(AllChars)
let digit* = ch(Digits)
proc str*(s: string): parserFnT {.inline.} =
return proc(parser: Parser): ParserResult =
@@ -243,12 +244,10 @@ when isMainModule:
block testParsingFunctions:
let ch1 = ch('1')
let chDigits = ch(Digits)
# Success
assert testParser123.flatMap(ch1).tokensToString() == "1"
assert testParser123.flatMap(anyCh).tokensToString() == "1"
assert testParser123.flatMap(chDigits).tokensToString() == "1"
assert testParser123.flatMap(str("123")).tokensToString() == "123"
# Mismatch