Add digit helper
This commit is contained in:
@@ -94,6 +94,7 @@ proc ch*(expectedChar: char): parserFnT {.inline.} =
|
|||||||
))
|
))
|
||||||
|
|
||||||
let anyCh* = ch(AllChars)
|
let anyCh* = ch(AllChars)
|
||||||
|
let digit* = ch(Digits)
|
||||||
|
|
||||||
proc str*(s: string): parserFnT {.inline.} =
|
proc str*(s: string): parserFnT {.inline.} =
|
||||||
return proc(parser: Parser): ParserResult =
|
return proc(parser: Parser): ParserResult =
|
||||||
@@ -243,12 +244,10 @@ when isMainModule:
|
|||||||
|
|
||||||
block testParsingFunctions:
|
block testParsingFunctions:
|
||||||
let ch1 = ch('1')
|
let ch1 = ch('1')
|
||||||
let chDigits = ch(Digits)
|
|
||||||
|
|
||||||
# Success
|
# Success
|
||||||
assert testParser123.flatMap(ch1).tokensToString() == "1"
|
assert testParser123.flatMap(ch1).tokensToString() == "1"
|
||||||
assert testParser123.flatMap(anyCh).tokensToString() == "1"
|
assert testParser123.flatMap(anyCh).tokensToString() == "1"
|
||||||
assert testParser123.flatMap(chDigits).tokensToString() == "1"
|
|
||||||
assert testParser123.flatMap(str("123")).tokensToString() == "123"
|
assert testParser123.flatMap(str("123")).tokensToString() == "123"
|
||||||
|
|
||||||
# Mismatch
|
# Mismatch
|
||||||
|
|||||||
Reference in New Issue
Block a user