[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 14:47:30 UTC 2010


The following commit has been merged in the master branch:
commit 56eb1ce9a4fa1804d2f70eaaa5e722d32b959e7a
Author: John Goerzen <jgoerzen at complete.org>
Date:   Fri Nov 19 01:34:40 2004 +0100

    Fixed eof problems
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--0.5--patch-76)

diff --git a/ChangeLog b/ChangeLog
index 605a52a..d966402 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,20 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
 #
 
+2004-11-18 18:34:40 GMT	John Goerzen <jgoerzen at complete.org>	patch-76
+
+    Summary:
+      Fixed eof problems
+    Revision:
+      missingh--head--0.5--patch-76
+
+
+    modified files:
+     ChangeLog libsrc/MissingH/ConfigParser/Lexer.hs
+     libsrc/MissingH/ConfigParser/Parser.hs
+     testsrc/ConfigParser/Parsertest.hs
+
+
 2004-11-18 17:26:26 GMT	John Goerzen <jgoerzen at complete.org>	patch-75
 
     Summary:
diff --git a/libsrc/MissingH/ConfigParser/Lexer.hs b/libsrc/MissingH/ConfigParser/Lexer.hs
index cd2b531..26eeefa 100644
--- a/libsrc/MissingH/ConfigParser/Lexer.hs
+++ b/libsrc/MissingH/ConfigParser/Lexer.hs
@@ -80,20 +80,17 @@ optionpair = do
              value <- optionvalue
              return (key, value)
 
-iloken :: Parser CPTok
-iloken =
+loken :: Parser [CPTok]
+loken =
     -- Ignore these things
-    do {eol; iloken}
-    <|> do {comment_line; iloken}
-    <|> do {empty_line; iloken}
+    do {eol; loken}
+    <|> do {comment_line; loken}
+    <|> do {empty_line; loken}
     
     -- Real stuff
-    <|> do {sname <- sectheader; return $ NEWSECTION sname}
-    <|> do {pair <- optionpair; return $ NEWOPTION pair}
-    <|> do {extension <- extension_line; return $ EXTENSIONLINE extension}
+    <|> do {sname <- sectheader; next <- loken; return $ NEWSECTION sname : next}
+    <|> do {pair <- optionpair; next <- loken; return $ NEWOPTION pair : next}
+    <|> do {extension <- extension_line; next <- loken; return $ EXTENSIONLINE extension : next}
+    <|> do {eof; return [EOFTOK]}
     <?> "Invalid syntax in configuration file"
-
-loken :: Parser [CPTok]
-loken = do
-        l <- manyTill iloken eof
-        return $ l ++ [EOFTOK]
+        
diff --git a/libsrc/MissingH/ConfigParser/Parser.hs b/libsrc/MissingH/ConfigParser/Parser.hs
index 7a8dfdd..4291420 100644
--- a/libsrc/MissingH/ConfigParser/Parser.hs
+++ b/libsrc/MissingH/ConfigParser/Parser.hs
@@ -33,32 +33,46 @@ Copyright (c) 2004 John Goerzen, jgoerzen\@complete.org
 -}
 module MissingH.ConfigParser.Parser
 (
- parse_string,
+ parse_string, parse_file, parse_handle, ParseOutput
        --satisfyG,
        --main
 ) where
 import Text.ParserCombinators.Parsec
 import MissingH.Str
 import MissingH.ConfigParser.Lexer
+import System.IO(Handle, hGetContents)
+
+type ParseOutput = [(String, [(String, String)])]
 
 ----------------------------------------------------------------------
 -- Exported funcs
 ----------------------------------------------------------------------
 
-parse_string :: String -> [(String, [(String, String)])]
+parse_string :: String -> ParseOutput
 parse_string s = 
     detokenize "(string)" $ parse loken "(string)" s
 
+parse_file :: FilePath -> IO ParseOutput
+parse_file f =
+    do o <- parseFromFile loken f
+       return $ detokenize f o
+
+parse_handle :: Handle -> IO ParseOutput
+parse_handle h =
+    do s <- hGetContents h
+       let o = parse loken (show h) s
+       return $ detokenize (show h) o
+
 ----------------------------------------------------------------------
 -- Private funcs
 ----------------------------------------------------------------------
 detokenize fp l =
     let r = case l of
-                   Left err -> error (show err)
+                   Left err -> error $ "Lexer: " ++ (show err)
                    Right reply -> reply
         in
         case runParser main () fp r of
-                                    Left err -> error (show err)
+                                    Left err -> error $ "Parser: " ++ (show err)
                                     Right reply -> reply
 
 main :: GenParser CPTok () [(String, [(String, String)])]
diff --git a/testsrc/ConfigParser/Parsertest.hs b/testsrc/ConfigParser/Parsertest.hs
index a3c9cc5..553e783 100644
--- a/testsrc/ConfigParser/Parsertest.hs
+++ b/testsrc/ConfigParser/Parsertest.hs
@@ -25,6 +25,10 @@ test_basic =
     let f inp exp = exp @=? parse_string inp in
         do
         f "" []
+        f "\n" []
+        f "#foo bar" []
+        f "#foo bar\n" []
+        f "[emptysect]" [("emptysect", [])]
         f "foo: bar" [("DEFAULT", [("foo", "bar")])]
 
 tests = TestList [TestLabel "test_basic" (TestCase test_basic)

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list