Added eof parser
[cc1516.git] / src / yard.icl
index 81e5883..582ea1d 100644 (file)
@@ -12,6 +12,7 @@ import Data.Either
 import Control.Monad
 import Control.Applicative
 from Data.Func import $
+import Data.Void
 
 instance toString Error where
        toString ParseError = "General parse error"
@@ -65,6 +66,11 @@ peek = Parser \i -> case i of
     []      = (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
 
@@ -75,4 +81,4 @@ item :: a -> Parser a a | Eq a
 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