[Haskell-cafe] An irritating Parsec problem

Evan Laforge qdunkan at gmail.com
Wed Oct 15 17:16:49 EDT 2008


Here's what I have in one file:

-- | Parse the text of an event with the given parser @p at .
parse :: (Monad m) => P.CharParser () a -> String -> Derive.DeriveT m a
parse p text = do
    (val, rest) <- case P.parse (p_rest p) "" text of
        Left err -> Derive.throw $
            "parse error on char " ++ show (P.sourceColumn (P.errorPos err))
            ++ " of " ++ show text ++ ": " ++ Seq.replace "\n" "; "
                (show_error_msgs (Parsec.Error.errorMessages err))
        Right val -> return val
    unless (null rest) $
        Derive.warn $ "trailing junk: " ++ show rest
    return val

-- Contrary to its documentation, showErrorMessages takes a set of strings
-- for translation, which makes it hard to use.
show_error_msgs = Parsec.Error.showErrorMessages
    "or" "unknown parse error" "expecting" "unexpected" "end of input"

p_rest :: P.GenParser tok st t -> P.GenParser tok st (t, [tok])
p_rest p = do
    val <- p
    rest <- P.getInput
    return (val, rest)



And this reminds me of something I was going to ask about: it would be
nice to fix either the documentation for showErrorMessages or the
implementation.  Preferably the implementation, because I can't see
the current implementation actually being useful for translation...


More information about the Haskell-Cafe mailing list