diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-03 22:57:10 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-03 22:57:10 +0200 |
| commit | 2b0b62b44a87536597050c525322c7bcc745bdb2 (patch) | |
| tree | 56ee143d427c66cb1f0583c07beec5f181abc983 /src/parser/Core.hs | |
| parent | 5e7d3a5ff586ac75b768a9a1c1f2d5b80960e821 (diff) | |
| download | computorv2-2b0b62b44a87536597050c525322c7bcc745bdb2.tar.gz computorv2-2b0b62b44a87536597050c525322c7bcc745bdb2.tar.bz2 computorv2-2b0b62b44a87536597050c525322c7bcc745bdb2.zip | |
Added polynom solver from computorv1, Added matrix multipilcation
Diffstat (limited to 'src/parser/Core.hs')
| -rw-r--r-- | src/parser/Core.hs | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/parser/Core.hs b/src/parser/Core.hs index 08ac1a9..5928fe4 100644 --- a/src/parser/Core.hs +++ b/src/parser/Core.hs @@ -3,9 +3,9 @@ module Parser.Core where import Control.Applicative -import Control.Monad import Data.Char + newtype Parser a = Parser { runParser :: String -> Either String (a, String) } runParserStrict :: Parser a -> String -> Either String a @@ -76,12 +76,6 @@ string s = sequenceA $ char <$> s sepBy :: Parser a -> Parser b -> Parser [a] sepBy x sepatator = (:) <$> x <*> (many (sepatator *> x)) --- sepByMap :: (b -> a -> a) -> Parser b -> Parser a -> Parser [a] --- sepByMap f sep x = (:) <$> x <*> (many (f <$> sep <*> x)) - --- chainl :: Parser a -> Parser (a -> a -> a) -> a -> Parser a --- chainl p op a = chainl1 p op <|> pure a - -- Parse one or more occurences of p separated by op -- Apply op in a left associative maner on each value in p chainl1 :: Parser a -> Parser (a -> a -> a) -> Parser a @@ -106,8 +100,13 @@ choice :: [Parser a] -> Parser a choice [] = empty choice (p:ps) = p <|> choice ps -alphaStringP :: Parser String -alphaStringP = some (satisfyChar isAlpha) +-- verify :: (a -> Bool) -> Parser a -> Parser a +-- verify predicate p = do a <- p +-- if predicate a then p else Parser (\_ -> Left "Bonjour") + +-- Parse a string of alpha character, converted to lower case +labelP :: Parser String +labelP = (map toLower) <$> some (satisfyChar isAlpha) floatP :: Parser Float @@ -116,7 +115,7 @@ floatP = signed unsignedP unsignedP :: Parser Float unsignedP = read <$> p where p = do pos <- digitsP - char '.' + _ <- char '.' dec <- digitsP return (pos ++ "." ++ dec) <|> digitsP @@ -124,7 +123,7 @@ floatP = signed unsignedP digitsP = some $ satisfyChar isDigit -- at least one digit to avoid read exception signed :: Num a => Parser a -> Parser a - signed p = do char '-' + signed p = do _ <- char '-' x <- p return (-x) <|> p |
