File tree Expand file tree Collapse file tree 4 files changed +8
-13
lines changed Expand file tree Collapse file tree 4 files changed +8
-13
lines changed Original file line number Diff line number Diff line change 31
31
32
32
instance lazy1ParserT :: Lazy1 (ParserT s m)
33
33
34
+ instance lazyParserT :: Lazy (ParserT s m a)
35
+
34
36
instance monadParserT :: (Monad m) => Monad (ParserT s m)
35
37
36
38
instance monadPlusParserT :: (Monad m) => MonadPlus (ParserT s m)
81
83
82
84
endBy1 :: forall m s a sep. (Monad m) => ParserT s m a -> ParserT s m sep -> ParserT s m [a]
83
85
84
- fix :: forall m s a. (ParserT m s a -> ParserT m s a) -> ParserT m s a
85
-
86
- fix2 :: forall m s a b. (Tuple (ParserT m s a) (ParserT m s b) -> Tuple (ParserT m s a) (ParserT m s b)) -> Tuple (ParserT m s a) (ParserT m s b)
87
-
88
86
option :: forall m s a. (Monad m) => a -> ParserT s m a -> ParserT s m a
89
87
90
88
optionMaybe :: forall m s a. (Functor m, Monad m) => ParserT s m a -> ParserT s m (Maybe a)
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import Control.Alt
8
8
import Control.Alternative
9
9
import Control.Monad.Eff
10
10
import Control.Monad.Identity
11
+ import Control.Lazy
11
12
12
13
import Debug.Trace
13
14
@@ -20,7 +21,7 @@ parens :: forall m a. (Monad m) => ParserT String m a -> ParserT String m a
20
21
parens = between (string " (" ) (string " )" )
21
22
22
23
nested :: forall m . (Functor m , Monad m ) => ParserT String m Number
23
- nested = fix $ \p -> (do
24
+ nested = fix1 $ \p -> (do
24
25
string " a"
25
26
return 0 ) <|> ((+) 1 ) <$> parens p
26
27
Original file line number Diff line number Diff line change @@ -84,6 +84,9 @@ instance monadStateParserT :: (Monad m) => MonadState s (ParserT s m) where
84
84
return $ case f s of
85
85
Tuple a s' -> { input: s', consumed: false , result: Right a }
86
86
87
+ instance lazyParserT :: Lazy (ParserT s m a ) where
88
+ defer f = ParserT $ \s -> unParserT (f unit) s
89
+
87
90
instance lazy1ParserT :: Lazy1 (ParserT s m ) where
88
91
defer1 f = ParserT $ \s -> unParserT (f unit) s
89
92
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import Data.Either
7
7
8
8
import Control.Alt
9
9
import Control.Alternative
10
+ import Control.Lazy
10
11
import Control.Monad
11
12
import Control.Monad.Error.Trans
12
13
import Control.Monad.Error.Class
@@ -15,14 +16,6 @@ import Control.Monad.State.Class
15
16
16
17
import Text.Parsing.Parser
17
18
18
- fix :: forall m s a . (ParserT m s a -> ParserT m s a ) -> ParserT m s a
19
- fix f = ParserT $ \s -> unParserT (f (fix f)) s
20
-
21
- fix2 :: forall m s a b . (Tuple (ParserT m s a ) (ParserT m s b ) -> Tuple (ParserT m s a ) (ParserT m s b )) -> Tuple (ParserT m s a ) (ParserT m s b )
22
- fix2 f = Tuple
23
- (ParserT $ \s -> unParserT (fst (f (fix2 f))) s)
24
- (ParserT $ \s -> unParserT (snd (f (fix2 f))) s)
25
-
26
19
(<?>) :: forall m s a . (Monad m ) => ParserT s m a -> String -> ParserT s m a
27
20
(<?>) p msg = p <|> fail (" Expected " ++ msg)
28
21
You can’t perform that action at this time.
0 commit comments