From 20984c20f2017633f62667ac5ae8951dde5a82db Mon Sep 17 00:00:00 2001 From: mrkkrp Date: Sat, 22 Aug 2015 01:12:26 +0600 Subject: [PATCH] =?UTF-8?q?cosmetic=20changes=20in=20=E2=80=98Text.Megapar?= =?UTF-8?q?sec.Prim=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also eliminated dead segment of code in ‘token'’. --- Text/Megaparsec/Prim.hs | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/Text/Megaparsec/Prim.hs b/Text/Megaparsec/Prim.hs index 012818f..6756ef2 100644 --- a/Text/Megaparsec/Prim.hs +++ b/Text/Megaparsec/Prim.hs @@ -364,9 +364,7 @@ parserPlus m n = ParsecT $ \s cok cerr eok eerr -> in unParser m s cok cerr eok meerr instance MonadTrans (ParsecT s u) where - lift amb = ParsecT $ \s _ _ eok _ -> do - a <- amb - eok a s mempty + lift amb = ParsecT $ \s _ _ eok _ -> amb >>= \a -> eok a s mempty -- Running a parser @@ -572,37 +570,16 @@ token :: Stream s m t => -> (t -> Maybe a) -- ^ Matching function for the token to parse. -> ParsecT s u m a {-# INLINE token #-} -token nextpos = token' nextpos Nothing - -token' :: Stream s m t => - (SourcePos -> t -> s -> SourcePos) - -> Maybe (SourcePos -> t -> s -> u -> u) - -> (t -> Maybe a) - -> ParsecT s u m a -{-# INLINE token' #-} -token' nextpos Nothing test - = ParsecT $ \(State input pos user) cok _ _ eerr -> do +token nextpos test = ParsecT $ \(State input pos u) cok _ _ eerr -> do r <- uncons input case r of Nothing -> eerr $ unexpectedErr eoi pos Just (c,cs) -> case test c of Just x -> let newpos = nextpos pos c cs - newstate = State cs newpos user + newstate = State cs newpos u in seq newpos $ seq newstate $ cok x newstate mempty Nothing -> eerr $ unexpectedErr (showToken c) pos -token' nextpos (Just nextState) test - = ParsecT $ \(State input pos user) cok _ _ eerr -> do - r <- uncons input - case r of - Nothing -> eerr $ unexpectedErr eoi pos - Just (c,cs) -> - case test c of - Just x -> let newpos = nextpos pos c cs - newUser = nextState pos c cs user - newstate = State cs newpos newUser - in seq newpos $ seq newstate $ cok x newstate mempty - Nothing -> eerr $ unexpectedErr (showToken c) pos -- | The parser @tokens posFromTok@ parses list of tokens and returns -- it. The resulting parser will use 'showToken' to pretty-print the