[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:48 UTC 2010
The following commit has been merged in the master branch:
commit b14f40e02396b3875761f836629ffdba1294245c
Author: John Goerzen <jgoerzen at complete.org>
Date: Fri Nov 19 08:36:57 2004 +0100
Switched to generalized token system for ConfigParser
Keywords:
(jgoerzen at complete.org--projects/missingh--head--0.5--patch-93)
diff --git a/ChangeLog b/ChangeLog
index b8f78f6..bb471a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,20 @@
# arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
#
+2004-11-19 01:36:57 GMT John Goerzen <jgoerzen at complete.org> patch-93
+
+ Summary:
+ Switched to generalized token system for ConfigParser
+ Revision:
+ missingh--head--0.5--patch-93
+
+
+ modified files:
+ ChangeLog libsrc/MissingH/ConfigParser/Lexer.hs
+ libsrc/MissingH/ConfigParser/Parser.hs
+ libsrc/MissingH/Parsec.hs
+
+
2004-11-19 01:20:05 GMT John Goerzen <jgoerzen at complete.org> patch-92
Summary:
diff --git a/libsrc/MissingH/ConfigParser/Lexer.hs b/libsrc/MissingH/ConfigParser/Lexer.hs
index 7096d03..2a91671 100644
--- a/libsrc/MissingH/ConfigParser/Lexer.hs
+++ b/libsrc/MissingH/ConfigParser/Lexer.hs
@@ -80,17 +80,21 @@ optionpair = do
value <- optionvalue
return (key, value)
-loken :: Parser [CPTok]
-loken =
+iloken :: Parser (GeneralizedToken CPTok)
+iloken =
-- Ignore these things
- do {eol; loken}
- <|> try (do {comment_line; loken})
- <|> try (do {empty_line; loken})
+ do {eol; iloken}
+ <|> try (do {comment_line; iloken})
+ <|> try (do {empty_line; iloken})
-- Real stuff
- <|> (do {sname <- sectheader; next <- loken; return $ NEWSECTION sname : next})
- <|> try (do {pair <- optionpair; next <- loken; return $ NEWOPTION pair : next})
- <|> (do {extension <- extension_line; next <- loken; return $ EXTENSIONLINE extension : next})
- <|> do {eof; return [EOFTOK]}
+ <|> (do {sname <- sectheader; togtok $ NEWSECTION sname})
+ <|> try (do {pair <- optionpair; togtok $ NEWOPTION pair})
+ <|> (do {extension <- extension_line; togtok $ EXTENSIONLINE extension})
+ <|> do {eof; togtok EOFTOK}
<?> "Invalid syntax in configuration file"
+loken :: Parser [GeneralizedToken CPTok]
+loken = do x <- manyTill iloken eof
+ y <- togtok EOFTOK
+ return $ x ++ [y]
diff --git a/libsrc/MissingH/ConfigParser/Parser.hs b/libsrc/MissingH/ConfigParser/Parser.hs
index 4291420..918eb8e 100644
--- a/libsrc/MissingH/ConfigParser/Parser.hs
+++ b/libsrc/MissingH/ConfigParser/Parser.hs
@@ -41,6 +41,7 @@ import Text.ParserCombinators.Parsec
import MissingH.Str
import MissingH.ConfigParser.Lexer
import System.IO(Handle, hGetContents)
+import MissingH.Parsec
type ParseOutput = [(String, [(String, String)])]
@@ -75,7 +76,7 @@ detokenize fp l =
Left err -> error $ "Parser: " ++ (show err)
Right reply -> reply
-main :: GenParser CPTok () [(String, [(String, String)])]
+main :: GeneralizedTokenParser CPTok () ParseOutput
main =
do {s <- sectionlist; return s}
<|> try (do
@@ -86,21 +87,11 @@ main =
<|> do {o <- optionlist; return $ [("DEFAULT", o)] }
<?> "Error parsing config file tokens"
-satisfyG :: (CPTok -> Bool) -> GenParser CPTok () CPTok
-satisfyG f = tokenPrim (\c -> show [c])
- (\pos _ _ -> pos)
- (\c -> if f c then Just c else Nothing)
-
-want :: (CPTok -> Maybe a) -> GenParser CPTok () a
-want f = tokenPrim (\c -> show [c])
- (\pos _ _ -> pos)
- (\c -> f c)
-
-sectionlist :: GenParser CPTok () [(String, [(String, String)])]
-sectionlist = do {satisfyG (==EOFTOK); return []}
+sectionlist :: GeneralizedTokenParser CPTok () ParseOutput
+sectionlist = do {satisfyg (==EOFTOK); return []}
<|> try (do
s <- sectionhead
- satisfyG (==EOFTOK)
+ satisfyg (==EOFTOK)
return [(s, [])]
)
<|> do
@@ -108,40 +99,40 @@ sectionlist = do {satisfyG (==EOFTOK); return []}
sl <- sectionlist
return (s : sl)
-section :: GenParser CPTok () (String, [(String, String)])
+section :: GeneralizedTokenParser CPTok () (String, [(String, String)])
section = do {sh <- sectionhead; ol <- optionlist; return (sh, ol)}
-sectionhead :: GenParser CPTok () String
+sectionhead :: GeneralizedTokenParser CPTok () String
sectionhead =
let wf (NEWSECTION x) = Just x
wf _ = Nothing
in
- do {s <- want wf; return $ strip s}
+ do {s <- tokeng wf; return $ strip s}
-optionlist :: GenParser CPTok () [(String, String)]
+optionlist :: GeneralizedTokenParser CPTok () [(String, String)]
optionlist =
try (do {c <- coption; ol <- optionlist; return $ c : ol})
<|> do {c <- coption; return $ [c]}
-extensionlist :: GenParser CPTok () [String]
+extensionlist :: GeneralizedTokenParser CPTok () [String]
extensionlist =
let wf (EXTENSIONLINE x) = Just x
wf _ = Nothing
in
- try (do {x <- want wf; l <- extensionlist; return $ x : l})
- <|> do {x <- want wf; return [x]}
+ try (do {x <- tokeng wf; l <- extensionlist; return $ x : l})
+ <|> do {x <- tokeng wf; return [x]}
-coption :: GenParser CPTok () (String, String)
+coption :: GeneralizedTokenParser CPTok () (String, String)
coption =
let wf (NEWOPTION x) = Just x
wf _ = Nothing
in
try (do
- o <- want wf
+ o <- tokeng wf
l <- extensionlist
return (strip (fst o), valmerge ((snd o) : l ))
)
- <|> do {o <- want wf; return $ (strip (fst o), strip (snd o))}
+ <|> do {o <- tokeng wf; return $ (strip (fst o), strip (snd o))}
valmerge :: [String] -> String
valmerge vallist =
diff --git a/libsrc/MissingH/Parsec.hs b/libsrc/MissingH/Parsec.hs
index 5f6709b..fd46117 100644
--- a/libsrc/MissingH/Parsec.hs
+++ b/libsrc/MissingH/Parsec.hs
@@ -34,7 +34,7 @@ module MissingH.Parsec(-- * Generalized Utilities
-- | These functions are generalized versions of
-- ones you might see in the Char parser.
GeneralizedToken, GeneralizedTokenParser,
- retgtok, tokeng, satisfyg, oneOfg, noneOfg,
+ togtok, tokeng, satisfyg, oneOfg, noneOfg,
specificg,
-- * Other Utilities
notMatching)
@@ -46,8 +46,8 @@ type GeneralizedToken a = (SourcePos, a)
type GeneralizedTokenParser a st b = GenParser (GeneralizedToken a) st b
{- | Generate (return) a 'GeneralizedToken'. -}
-retgtok :: a -> GenParser b st (GeneralizedToken a)
-retgtok tok = do
+togtok :: a -> GenParser b st (GeneralizedToken a)
+togtok tok = do
x <- getPosition
return (x, tok)
--
haskell-testpack
More information about the Pkg-haskell-commits
mailing list