Fixing token handling

This commit is contained in:
Zoe Roux
2021-11-08 15:15:50 +01:00
parent 87021e04f1
commit 0af5e3e5f5
2 changed files with 12 additions and 2 deletions

View File

@@ -64,7 +64,10 @@ pString (x:xs) = do
pString [] = pure ""
pToken :: Parser String
pToken = pUntil (\x -> isSpace x || x == ')' || x == '(')
pToken = Parser $ \x ->
case parse (pUntil (\x -> isSpace x || x == ')' || x == '(')) x of
(Just ".", lo) -> (Nothing, '.':lo)
ret -> ret
pDigit :: Parser Char
pDigit = pCharIf isDigit

View File

@@ -12,9 +12,16 @@ charIfTest = "charIf isSpace ' 1 23'," ~: (Just ' ', "1 23") ~=? parse (pCharIf
charIfFailureTest :: Test
charIfFailureTest = "charIf isSpace '1 23'," ~: (Nothing, "1 23") ~=? parse (pCharIf isSpace) "1 23"
tokenDotTest :: Test
tokenDotTest = "pToken \".\"" ~: (Nothing, ".") ~=? parse pToken "."
tokenSpaceTest :: Test
tokenSpaceTest = "pToken \"1 2\"" ~: (Just "1", " 2") ~=? parse pToken "1 2"
tests :: Test
tests = TestList [
TestLabel "Basic parser" charTest, charIfTest, charIfFailureTest
TestLabel "Basic parser" charTest, charIfTest, charIfFailureTest,
TestLabel "Token parser" tokenDotTest, tokenSpaceTest
]
main :: IO ()