From 0ddf8ff18d1bca99e925873f7927ffe64376aebc Mon Sep 17 00:00:00 2001 From: krasimir Date: Tue, 17 Nov 2009 21:49:51 +0000 Subject: [PATCH] slight optimization in GF.Grammar.Lexer --- src/GF/Grammar/Lexer.x | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/GF/Grammar/Lexer.x b/src/GF/Grammar/Lexer.x index bc1a2277f..d6f49bbb1 100644 --- a/src/GF/Grammar/Lexer.x +++ b/src/GF/Grammar/Lexer.x @@ -234,23 +234,23 @@ data AlexInput = AI {-# UNPACK #-} !Posn -- current position, {-# UNPACK #-} !BS.ByteString -- current input string data ParseResult a - = POk AlexInput a + = POk a | PFailed Posn -- The position of the error String -- The error message newtype P a = P { unP :: AlexInput -> ParseResult a } instance Monad P where - return a = a `seq` (P $ \s -> POk s a) + return a = a `seq` (P $ \s -> POk a) (P m) >>= k = P $ \ s -> case m s of - POk s1 a -> unP (k a) s1 + POk a -> unP (k a) s PFailed posn err -> PFailed posn err fail msg = P $ \(AI posn _ _) -> PFailed posn msg runP :: P a -> BS.ByteString -> Either (Posn,String) a runP (P f) txt = case f (AI (Pn 1 0) ' ' txt) of - POk _ x -> Right x + POk x -> Right x PFailed pos msg -> Left (pos,msg) failLoc :: Posn -> String -> P a @@ -267,6 +267,6 @@ lexer cont = P go AlexToken inp' len act -> unP (cont (act pos (BS.take len str))) inp' getPosn :: P Posn -getPosn = P $ \inp@(AI pos _ _) -> POk inp pos +getPosn = P $ \inp@(AI pos _ _) -> POk pos }