From: Mart Lubbers Date: Wed, 16 Mar 2016 12:25:03 +0000 (+0100) Subject: updated that the parser fails when parsing not everything X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=fc38bf6ef5716c685ac316fdf3c42e7afce327eb;p=cc1516.git updated that the parser fails when parsing not everything --- diff --git a/AST.dcl b/AST.dcl index 9132067..0d8644f 100644 --- a/AST.dcl +++ b/AST.dcl @@ -3,16 +3,7 @@ definition module AST from Data.Maybe import :: Maybe from StdOverloaded import class toString -/* - * Type errors can happen in either - * - variable declarations (x :: Int = True) - * - function declarations (f :: (Char -> Int) = (+)1) - * - Expressions (1 + 'a') - * So these are the items that will get position metadata - */ - :: Pos = {line :: Int, col :: Int} - :: AST = AST [VarDecl] [FunDecl] :: VarDecl = VarDecl Pos Type String Expr :: Type @@ -38,7 +29,6 @@ from StdOverloaded import class toString :: Op1 = UnNegation | UnMinus :: Op2 = BiPlus | BiMinus | BiTimes | BiDivide | BiMod | BiEquals | BiLesser | BiGreater | BiLesserEq | BiGreaterEq | BiUnEqual | BiAnd | BiOr | BiCons - :: FunDecl = FunDecl Pos String [String] (Maybe FunType) [VarDecl] [Stmt] :: FunType = FunType [Type] (Maybe Type) :: FunCall = FunCall String [Expr] diff --git a/parse.icl b/parse.icl index 34ec15b..9aabea3 100644 --- a/parse.icl +++ b/parse.icl @@ -20,7 +20,10 @@ import AST parser :: LexerOutput -> ParserOutput parser (Left e) = Left e -parser (Right r) = fst $ runParser parseProgram r +parser (Right r) = case runParser parseProgram r of + (Right ast, [(p, t):xs]) = Left $ PositionalError p.line p.col ( + "Unable to parse from: " +++ printToString t) + x = fst x parseProgram :: Parser Token AST parseProgram = AST <$> (many parseVarDecl) <*> (some parseFunDecl) diff --git a/spl.icl b/spl.icl index 2b458e4..f398f90 100644 --- a/spl.icl +++ b/spl.icl @@ -24,7 +24,6 @@ from yard import :: Error, instance toString Error program :: String, lex :: Bool, parse :: Bool, - selftest :: Bool, fp :: Maybe String, help :: Bool} @@ -50,7 +49,6 @@ Start w <<< " --version Show the version\n" <<< " --[no-]lex Lexer output(default: disabled)\n" <<< " --[no-]parse Parser output(default: enabled)\n" - <<< " --[no-]selftest Feed pprint parse back(default: disabled)\n" = snd $ fclose stdin w # (contents, stdin, w) = readFileOrStdin stdin args.fp w = case contents of @@ -82,7 +80,6 @@ parseArgs w version=False, lex=False, parse=True, - selftest=False, fp=Nothing, help=False}, w) where @@ -94,8 +91,6 @@ where pa ["--no-lex":r] o = pa r {o & lex=False} pa ["--parse":r] o = pa r {o & parse=True} pa ["--no-parse":r] o = pa r {o & parse=False} - pa ["--selftest":r] o = pa r {o & selftest=True} - pa ["--no-selftest":r] o = pa r {o & selftest=False} pa [x:r] o = pa r {o & fp=Just x} readFileOrStdin :: *File (Maybe String) *World -> *(Either String [Char], *File, *World)