X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=src%2Fyard.icl;h=278bac861d8ccf8d1b8e4fa90b8d2ab23496b843;hb=a0cf809b53126a797667fb43f8496a7cc2b7252e;hp=546031252484cb5b98a3c0f540c5b7623bfa94e7;hpb=051a7614b88beaea2912dd9f76d04d9a90ec2f99;p=cc1516.git diff --git a/src/yard.icl b/src/yard.icl index 5460312..278bac8 100644 --- a/src/yard.icl +++ b/src/yard.icl @@ -15,8 +15,8 @@ instance toString Error where toString (LexError e) = "Lexer error: " +++ e instance + Error where - (+) (Expected as) (Expected bs) = Expected (as++bs) - (+) _ r = r + (+) (Expected as _) (Expected bs p) = Expected (as++bs) p + (+) _ r = r runParser :: (Parser a b) [a] -> (Either Error b, [a]) runParser (Parser f) i = f i @@ -41,9 +41,10 @@ instance Alternative (Parser a) where (Right r, rest) = (Right r, rest) (Left e2, rest) = (Left (e1+e2), rest) - :: (Parser a b) String -> Parser a b - p e = Parser \i -> case runParser p i of - (Left e1, rest) = (Left (e1+(Expected [e])), rest) +//Try the parser, if it fails decorate the error with Expected of the given String and position +() :: (Parser a b) (String, Int) -> Parser a b +() p (e,pos) = Parser \i -> case runParser p i of + (Left e1, rest) = let error = (e1+(Expected [e] pos)) in (Left error, rest) (Right r, rest) = (Right r, rest) fail :: Parser a b