summaryrefslogtreecommitdiff
path: root/Parsers.hs
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-02-13 23:53:27 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-02-13 23:53:27 +1300
commita17f9ba31d682f18c5e25d07bd94d2ccfb6de6d0 (patch)
tree2781e71b78ab8ac27723a7cde82396d02e440130 /Parsers.hs
parenta1229c7403f83a525b1bdb0e9b140f032706128c (diff)
Able to parse simple operations
Diffstat (limited to 'Parsers.hs')
-rw-r--r--Parsers.hs12
1 files changed, 12 insertions, 0 deletions
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 []
+