mirror of
https://github.com/zoriya/HAL.git
synced 2025-12-06 06:36:09 +00:00
Fixing token handling
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 ()
|
||||
|
||||
Reference in New Issue
Block a user