From 22d41fc6a5b0f55dab587b43f1c7fc9ef4b40065 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 6 Jun 2020 13:56:54 +0200 Subject: Ugly and not working function value reduction, main evaluation refactoring --- src/parser/Core.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/parser/Core.hs') diff --git a/src/parser/Core.hs b/src/parser/Core.hs index 64e0b84..85652a0 100644 --- a/src/parser/Core.hs +++ b/src/parser/Core.hs @@ -6,12 +6,13 @@ import Control.Applicative import Data.Char -newtype Parser a = Parser { runParser :: String -> Either String (a, String) } +type Result a = Either String a +newtype Parser a = Parser { runParser :: String -> Result (a, String) } -runParserStrict :: Parser a -> String -> Either String a +runParserStrict :: Parser a -> String -> Result a runParserStrict p input = case runParser p input of Right (a, "") -> Right a - Right (_, rest) -> Left $ "Unconsumed input: \"" ++ rest ++ "\"" + Right (_, rest) -> Left $ "Unexpected string: \"" ++ rest ++ "\"" Left err -> Left err ------------------------------------------------------------------------------- @@ -43,15 +44,15 @@ instance Monad Parser where -- instance for Either String so that it can be used in the Alternative for Parser instance Alternative (Either String) where - -- empty :: Either String a + -- empty :: Result a empty = Left "" - -- (<|>) :: Either String a -> Either String a -> Either String a + -- (<|>) :: Result a -> Result a -> Result a Left _ <|> x2 = x2 x1 <|> _ = x1 instance Alternative Parser where -- empty :: Parser a - empty = Parser (\_ -> Left "Empty") + empty = Parser (\_ -> empty) -- (<|>) :: Parser a -> Parser a -> Parser a (Parser p1) <|> (Parser p2) = Parser $ \s -> p1 s <|> p2 s @@ -111,7 +112,6 @@ varLabelP = (map toLower <$> some (satisfyChar isAlpha)) >>= verify (/= "i") funLabelP :: Parser String funLabelP = map toLower <$> some (satisfyChar isAlpha) - floatP :: Parser Float floatP = signed unsignedP where -- cgit