Implement Alternative Parser

This commit is contained in:
Laborratte 5 2024-07-17 21:20:04 +02:00
parent 3deaeee24a
commit 39d77eafe0
Signed by: Laborratte5
GPG key ID: 3A30072E35202C02

View file

@ -37,3 +37,9 @@ instance Applicative Parser where
Just (rest, f) -> case a rest of Just (rest, f) -> case a rest of
Nothing -> Nothing Nothing -> Nothing
Just (rest', x) -> Just (rest', f x) Just (rest', x) -> Just (rest', f x)
instance Alternative Parser where
empty = Parser $ const Nothing
(<|>) (Parser p1) (Parser p2) = Parser $ \input -> case p1 input of
Nothing -> p2 input
result -> result