diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2012-07-24 22:42:21 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2012-07-24 22:45:22 -0700 |
commit | fbd3d2b4503c486f7d835697252ce8b1e39eea3e (patch) | |
tree | 03cd63a4acf29852c2a4f3b8cf4c5ff842f37fde /src/Text | |
parent | 02ef26ae91f7c1db1e4018c69b33f59c3ce837a2 (diff) |
Better algorithm for oneOfStrings.
This goes character by character, not backtracking.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Parsing.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs index c04db4d60..145ad64c5 100644 --- a/src/Text/Pandoc/Parsing.hs +++ b/src/Text/Pandoc/Parsing.hs @@ -173,9 +173,16 @@ notFollowedBy' p = try $ join $ do a <- try p return (return ()) -- (This version due to Andrew Pimlott on the Haskell mailing list.) --- | Parses one of a list of strings (tried in order). +-- | Parses one of a list of strings (tried in order). oneOfStrings :: [String] -> Parsec [Char] st String -oneOfStrings listOfStrings = choice $ map (try . string) listOfStrings +oneOfStrings [] = fail "no strings" +oneOfStrings strs = do + c <- anyChar + let strs' = [xs | (x:xs) <- strs, x == c] + case strs' of + [] -> fail "not found" + z | "" `elem` z -> return [c] + | otherwise -> (c:) `fmap` oneOfStrings strs' -- | Parses a space or tab. spaceChar :: Parsec [Char] st Char |