diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-06 13:56:54 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-06 14:19:15 +0200 |
| commit | 22d41fc6a5b0f55dab587b43f1c7fc9ef4b40065 (patch) | |
| tree | 4055b2cfa98ef2a3661b727193e0f747b01cb9f7 /src/parser/Core.hs | |
| parent | f5ddd91d290a0c508e04cce2cb19c4c8bae32835 (diff) | |
| download | computorv2-master.tar.gz computorv2-master.tar.bz2 computorv2-master.zip | |
Diffstat (limited to 'src/parser/Core.hs')
| -rw-r--r-- | src/parser/Core.hs | 14 |
1 files changed, 7 insertions, 7 deletions
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 |
