Another structure overhaul
This commit is contained in:
parent
3b0de65de1
commit
0720f3b719
14 changed files with 158 additions and 148 deletions
20
lib/RPGEngine/Parse/Core.hs
Normal file
20
lib/RPGEngine/Parse/Core.hs
Normal file
|
@ -0,0 +1,20 @@
|
|||
module RPGEngine.Parse.Core 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 ()}
|
Reference in a new issue