@@ -41,7 +41,7 @@ unParserT (ParserT p) = p
41
41
-- | Apply a parser, keeping only the parsed result.
42
42
runParserT :: forall m s a . Monad m => PState s -> ParserT s m a -> m (Either ParseError a )
43
43
runParserT s p = do
44
- ( Result _ result _ _) <- unParserT p s
44
+ Result _ result _ _ <- unParserT p s
45
45
pure result
46
46
47
47
-- | The `Parser` monad is a synonym for the parser monad transformer applied to the `Identity` monad.
@@ -52,19 +52,19 @@ runParser :: forall s a. s -> Parser s a -> Either ParseError a
52
52
runParser s = runIdentity <<< runParserT (PState s initialPos)
53
53
54
54
instance functorParserT :: (Functor m ) => Functor (ParserT s m ) where
55
- map f p = ParserT $ \s -> f' <$> unParserT p s
55
+ map f p = ParserT \s -> f' <$> unParserT p s
56
56
where
57
57
f' (Result input result consumed pos) = Result input (f <$> result) consumed pos
58
58
59
59
instance applyParserT :: Monad m => Apply (ParserT s m ) where
60
60
apply = ap
61
61
62
62
instance applicativeParserT :: Monad m => Applicative (ParserT s m ) where
63
- pure a = ParserT $ \(PState s pos) -> do
63
+ pure a = ParserT \(PState s pos) -> do
64
64
pure (Result s (Right a) false pos)
65
65
66
66
instance altParserT :: Monad m => Alt (ParserT s m ) where
67
- alt p1 p2 = ParserT $ \s -> do
67
+ alt p1 p2 = ParserT \s -> do
68
68
(o@(Result input result consumed pos)) <- unParserT p1 s
69
69
case result of
70
70
Left _ | not consumed -> unParserT p2 s
@@ -76,7 +76,7 @@ instance plusParserT :: Monad m => Plus (ParserT s m) where
76
76
instance alternativeParserT :: Monad m => Alternative (ParserT s m )
77
77
78
78
instance bindParserT :: Monad m => Bind (ParserT s m ) where
79
- bind p f = ParserT $ \s -> do
79
+ bind p f = ParserT \s -> do
80
80
(Result input result consumed pos) <- unParserT p s
81
81
case result of
82
82
Left err -> pure (Result input (Left err) consumed pos)
@@ -91,23 +91,23 @@ instance monadZeroParserT :: Monad m => MonadZero (ParserT s m)
91
91
instance monadPlusParserT :: Monad m => MonadPlus (ParserT s m )
92
92
93
93
instance monadTransParserT :: MonadTrans (ParserT s ) where
94
- lift m = ParserT $ \(PState s pos) -> (\a -> Result s (Right a) false pos) <$> m
94
+ lift m = ParserT \(PState s pos) -> (\a -> Result s (Right a) false pos) <$> m
95
95
96
96
instance monadStateParserT :: Monad m => MonadState s (ParserT s m ) where
97
- state f = ParserT $ \(PState s pos) ->
97
+ state f = ParserT \(PState s pos) ->
98
98
pure $ case f s of
99
99
Tuple a s' -> Result s' (Right a) false pos
100
100
101
101
instance lazyParserT :: Lazy (ParserT s m a ) where
102
- defer f = ParserT $ \s -> unParserT (f unit) s
102
+ defer f = ParserT \s -> unParserT (f unit) s
103
103
104
104
-- | Set the consumed flag.
105
105
consume :: forall s m . Monad m => ParserT s m Unit
106
- consume = ParserT $ \(PState s pos) -> pure (Result s (Right unit) true pos)
106
+ consume = ParserT \(PState s pos) -> pure (Result s (Right unit) true pos)
107
107
108
108
-- | Fail with a message.
109
109
fail :: forall m s a . Monad m => String -> ParserT s m a
110
- fail message = ParserT $ \(PState s pos) -> pure $ parseFailed s pos message
110
+ fail message = ParserT \(PState s pos) -> pure $ parseFailed s pos message
111
111
112
112
-- | Creates a failed parser state for the remaining input `s` and current position
113
113
-- | with an error message.
0 commit comments