summaryrefslogtreecommitdiff
path: root/parser
diff options
context:
space:
mode:
Diffstat (limited to 'parser')
-rw-r--r--parser/main.hs9
1 files changed, 3 insertions, 6 deletions
diff --git a/parser/main.hs b/parser/main.hs
index 9840980..843f9a5 100644
--- a/parser/main.hs
+++ b/parser/main.hs
@@ -26,18 +26,12 @@ instance Monad (Parser a) where
where g inp = case parse p inp of Just (a,b) -> parse (f a) b
_ -> Nothing
-parse :: Parser a b -> a -> Maybe (b,a)
parse (Parser f) inp = f inp
satisfy :: (Char -> Bool) -> Parser String Char
satisfy f = Parser g where g (x:xs) | f x = Just (x,xs)
g _ = Nothing
-word :: String -> Parser String String
-word w = Parser g where l = length w
- g inp = if take l inp == w then Just (w,drop l inp)
- else Nothing
-
space :: Parser String Char
space = satisfy (==' ')
@@ -50,6 +44,9 @@ notChar c = satisfy (/=c)
num :: Parser String Int
num = read <$> some (satisfy isDigit)
+word :: String -> Parser String String
+word (c:cs) = (:) <$> char c <*> word cs
+word _ = pure ""
parseOp op sig = (pure (op) <* many space <*> num <* many space <* char sig <* many space <*> num )
parseOps = (parseOp (+) '+' <|> parseOp (-) '-' <|> parseOp (*) '*' <|> parseOp (div) '/')