From a17f9ba31d682f18c5e25d07bd94d2ccfb6de6d0 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Mon, 13 Feb 2023 23:53:27 +1300 Subject: Able to parse simple operations --- Parsers.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Parsers.hs') diff --git a/Parsers.hs b/Parsers.hs index 54d85a5..96c4a07 100644 --- a/Parsers.hs +++ b/Parsers.hs @@ -120,3 +120,15 @@ stopAfter p = (,) <$> stopAt p <*> p stopIf :: Parser t a -> Parser t [t] stopIf p = stopAt $ () <$ p <|> eof +firstOf :: [Parser t a] -> Parser t a +firstOf = foldr1 (<|>) + +sepBy1 :: Parser t a -> Parser t b -> Parser t [a] +sepBy1 a b = do + x <- a + xs <- mult $ b >> a + return $ x:xs + +sepBy :: Parser t a -> Parser t b -> Parser t [a] +sepBy a b = sepBy1 a b <|> pure [] + -- cgit v1.2.1