File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ module Lib
44
55import Data.Char
66import Data.Either
7- import Control.Applicative
7+ import Control.Applicative hiding ( many )
88
99someFunc :: IO ()
1010someFunc = putStrLn " someFunc"
@@ -28,6 +28,18 @@ jsonBool = strToJsonBool <$> (string "true" <|> string "false")
2828 strToJsonBool " false" = JsonBool False
2929 strToJsonBool _ = undefined
3030
31+ jsonNumber :: Parser JsonValue
32+ jsonNumber = lstToInt <$> number
33+ where
34+ lstToInt nms = JsonNumber $ read $ map intToDigit nms
35+
36+ stringLiteral :: Parser [Char ]
37+ stringLiteral = many $ satisfy (/= ' "' )
38+
39+ -- mo escape support
40+ jsonString :: Parser JsonValue
41+ jsonString = (\ str -> JsonString str) <$> (char ' "' *> stringLiteral <* char ' "' )
42+
3143newtype Parser a = Parser { runParser :: String -> Either String (a , String ) }
3244
3345instance Functor Parser where
@@ -71,3 +83,8 @@ digit = digitToInt <$> satisfy isDigit
7183string :: String -> Parser String
7284string str = sequenceA $ map char str
7385
86+ many p = (:) <$> p <*> many p <|> pure []
87+
88+ many1 p = (:) <$> p <*> (many p <|> pure [] )
89+
90+ number = many1 digit
You can’t perform that action at this time.
0 commit comments