]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Parser.hs
multipart/form-data and more
[Lucu.git] / Network / HTTP / Lucu / Parser.hs
index 5671ec0ccdf8c1c505a9bdf20cd227d8b1e07ec0..bbe16a3d80b8bd3d4da6f2263fbe995f9cf3fd75 100644 (file)
@@ -93,8 +93,8 @@ instance Monad Parser where
 failP :: Parser a
 failP = fail undefined
 
--- |@'parse' p bstr@ parses @bstr@ with @p@ and returns @(result,
--- remaining)@.
+-- |@'parse' p bstr@ parses @bstr@ with @p@ and returns @(result,
+-- remaining #)@.
 parse :: Parser a -> LazyByteString -> (# ParserResult a, LazyByteString #)
 parse p input -- input は lazy である必要有り。
     = p `seq`
@@ -144,7 +144,7 @@ allowEOF f = f `seq`
 satisfy :: (Char -> Bool) -> Parser Char
 satisfy f = f `seq`
             do c <- anyChar
-               if f c then
+               if f $! c then
                    return c
                  else
                    failP
@@ -167,7 +167,7 @@ infixr 0 <|>
 (<|>) :: Parser a -> Parser a -> Parser a
 f <|> g
     = f `seq` g `seq`
-      Parser $! do saved <- get -- 状態を保存
+      Parser $! do saved  <- get -- 状態を保存
                    result <- runParser f
                    case result of
                      Success a    -> return $! Success a
@@ -185,8 +185,17 @@ oneOf = foldl (<|>) failP . map char
 
 
 notFollowedBy :: Parser a -> Parser ()
-notFollowedBy p = p `seq`
-                  (p >> failP) <|> return ()
+notFollowedBy p
+    = p `seq`
+      Parser $! do saved  <- get -- 状態を保存
+                   result <- runParser p
+                   case result of
+                     Success a    -> do put saved -- 状態を復歸
+                                        return IllegalInput
+                     IllegalInput -> do put saved -- 状態を復歸
+                                        return $! Success ()
+                     ReachedEOF   -> do put saved -- 状態を復歸
+                                        return $! Success ()
 
 
 digit :: Parser Char