from Data.Functor import class Functor
from Control.Monad import class Monad
from Control.Applicative import class Applicative, class Alternative
+import Data.Void
:: Error = ParseError | LexError String | Unexpected String Int
:: Parser a b = Parser ([a] -> (Either Error b, [a]))
check :: (a -> Bool) -> Parser a a
item :: a -> Parser a a | Eq a
list :: [a] -> Parser a [a] | Eq a
+eof :: Parser a Void
import Control.Monad
import Control.Applicative
from Data.Func import $
+import Data.Void
instance toString Error where
toString ParseError = "General parse error"
[] = (Left ParseError, [])
[x:xs] = (Right x, [x:xs])
+eof :: Parser a Void
+eof = Parser \i -> case i of
+ [] = (Right Void, [])
+ _ = (Left ParseError, i)
+
satisfy :: (a -> Bool) -> Parser a a
satisfy f = top >>= \r -> if (f r) (return r) fail
item a = satisfy ((==)a)
list :: [a] -> Parser a [a] | Eq a
-list as = mapM item as
+list as = mapM item as
\ No newline at end of file