From: pimjager Date: Mon, 29 Feb 2016 13:02:16 +0000 (+0100) Subject: Errors: changed expected to unexpected, but this reports outermost failing parser... X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=3944a17b55128c2b75bf1948bbf0561a4b6ca783;p=cc1516.git Errors: changed expected to unexpected, but this reports outermost failing parser instead of intermost failing parser --- diff --git a/src/example.spl b/src/example.spl index 58d037e..b3f6b95 100644 --- a/src/example.spl +++ b/src/example.spl @@ -3,7 +3,7 @@ First the recursive version . */ facR(n) :: Int -> Int { - if (n < 2) { + if (n }< 2) { return 1; } else { return n * facR(n-1); diff --git a/src/main.prj b/src/main.prj index 7ba18dc..f2d50f9 100644 --- a/src/main.prj +++ b/src/main.prj @@ -31,6 +31,7 @@ Global Link LinkMethod: Static GenerateRelocations: False + GenerateSymbolTable: False GenerateLinkMap: False LinkResources: False ResourceSource: @@ -421,7 +422,7 @@ OtherModules Fusion: False Module Name: Control.Applicative - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -435,7 +436,7 @@ OtherModules Fusion: False Module Name: Control.Monad - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -449,7 +450,7 @@ OtherModules Fusion: False Module Name: Data.Either - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -463,7 +464,7 @@ OtherModules Fusion: False Module Name: Data.Foldable - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -477,7 +478,7 @@ OtherModules Fusion: False Module Name: Data.Func - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -491,7 +492,7 @@ OtherModules Fusion: False Module Name: Data.Functor - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -505,7 +506,7 @@ OtherModules Fusion: False Module Name: Data.List - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -519,7 +520,7 @@ OtherModules Fusion: False Module Name: Data.Map - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -533,7 +534,7 @@ OtherModules Fusion: False Module Name: Data.Maybe - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -547,7 +548,7 @@ OtherModules Fusion: False Module Name: Data.Monoid - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -561,7 +562,7 @@ OtherModules Fusion: False Module Name: Data.Set - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -575,7 +576,7 @@ OtherModules Fusion: False Module Name: Data.Traversable - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -589,7 +590,7 @@ OtherModules Fusion: False Module Name: Data.Void - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -603,7 +604,7 @@ OtherModules Fusion: False Module Name: System.CommandLine - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -617,7 +618,7 @@ OtherModules Fusion: False Module Name: System.IO - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -631,7 +632,7 @@ OtherModules Fusion: False Module Name: System._Pointer - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -645,7 +646,7 @@ OtherModules Fusion: False Module Name: Text - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -659,7 +660,7 @@ OtherModules Fusion: False Module Name: Text.JSON - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -673,7 +674,7 @@ OtherModules Fusion: False Module Name: Text.PPrint - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Independent + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent Compiler NeverMemoryProfile: False NeverTimeProfile: False @@ -701,7 +702,7 @@ OtherModules Fusion: False Module Name: System.OS - Dir: {Application}/lib/iTasks-SDK/Dependencies/Platform/OS-Linux-64 + Dir: {Application}/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Mac Compiler NeverMemoryProfile: False NeverTimeProfile: False diff --git a/src/parse.icl b/src/parse.icl index 9fa1377..f57c5e5 100644 --- a/src/parse.icl +++ b/src/parse.icl @@ -176,7 +176,7 @@ trans1 t r = trans2 t $ const r derive gPrint TokenValue derive gEq TokenValue satTok :: TokenValue -> Parser Token Token -satTok t = top >>= \tok=:(pos, tv) -> if (eq t tok) (return tok) (fail (printToString t, pos)) +satTok t = top >>= \tok=:(pos, tv) -> if (eq t tok) (return tok) (fail (printToString tv, pos)) where eq (IdentToken _) (_, IdentToken _) = True eq (NumberToken _) (_, NumberToken _) = True diff --git a/src/yard.dcl b/src/yard.dcl index 73a82c0..dff75d9 100644 --- a/src/yard.dcl +++ b/src/yard.dcl @@ -7,7 +7,7 @@ from Data.Functor import class Functor from Control.Monad import class Monad from Control.Applicative import class Applicative, class Alternative -:: Error = ParseError | LexError String | Expected [String] Int +:: Error = ParseError | LexError String | Unexpected String Int :: Parser a b = Parser ([a] -> (Either Error b, [a])) instance Functor (Parser a) diff --git a/src/yard.icl b/src/yard.icl index 932999a..bded7fb 100644 --- a/src/yard.icl +++ b/src/yard.icl @@ -16,16 +16,16 @@ from Data.Func import $ instance toString Error where toString ParseError = "General parse error" toString (LexError e) = "Lexer error: " +++ e - toString (Expected ts pos) = "Expected " +++ (concat $ intersperse ", " ts) - +++ " at position " +++ (toString pos) - -instance + Error where - (+) (Expected as _) (Expected bs p) = Expected (as++bs) p - (+) _ r = r + toString (Unexpected e pos) = "Unexpected " +++ e +++ " at position " +++ (toString pos) runParser :: (Parser a b) [a] -> (Either Error b, [a]) runParser (Parser f) i = f i +instance + Error where + (+) ParseError r = r + (+) r ParseError = r + (+) _ r = r + instance Functor (Parser a) where fmap f m = liftM f m @@ -43,13 +43,13 @@ instance Alternative (Parser a) where (<|>) p1 p2 = Parser \i -> case runParser p1 i of (Right r, rest) = (Right r, rest) (Left e1, rest) = case runParser p2 i of + (Left e2, rest) = (Left $ e1+e2, rest) (Right r, rest) = (Right r, rest) - (Left e2, rest) = (Left (e1+e2), 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) + (Left e1, rest) = (Left $ e1 + Unexpected e pos, rest) (Right r, rest) = (Right r, rest) fail :: Parser a b