module RPGEngine.Internals.Parse where import Text.Parsec import Text.Parsec.String -- A wrapper, which takes a parser and some input and returns a -- parsed output. parseWith :: Parser a -> String -> Either ParseError a parseWith parser = parse parser "" -- Also return anything that has not yet been parsed parseWithRest :: Parser a -> String -> Either ParseError (a, String) -- fmap (,) over Parser monad and apply to rest parseWithRest parser = parse ((,) <$> parser <*> rest) "" where rest = manyTill anyToken eof -- Ignore all kinds of whitespaces ignoreWS :: Parser a -> Parser a ignoreWS parser = choice [skipComment, spaces] >> parser where skipComment = do{ string "#"; manyTill anyChar endOfLine; return ()}