From 54de7e7e1cf7a05f37976d81c0f978ad486551a0 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 3 Nov 2012 16:27:17 -0700 Subject: [PATCH] Added warnings for then;, else; --- shpell.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/shpell.hs b/shpell.hs index 82d961b..b0a6a32 100644 --- a/shpell.hs +++ b/shpell.hs @@ -683,6 +683,8 @@ readCmdWord = do return f prop_readIfClause = isOk readIfClause "if false; then foo; elif true; then stuff; more stuff; else cows; fi" +prop_readIfClause2 = isWarning readIfClause "if false; then; echo oo; fi" +prop_readIfClause3 = isWarning readIfClause "if false; then true; else; echo lol fi" readIfClause = do id <- getNextId (condition, action) <- readIfPart @@ -696,6 +698,7 @@ readIfPart = do allspacing condition <- readTerm g_Then + optional (g_Semi >> parseProblem ErrorC "No semicolons directly after 'then'") allspacing action <- readTerm return (condition, action) @@ -705,12 +708,14 @@ readElifPart = do allspacing condition <- readTerm g_Then + optional (g_Semi >> parseProblem ErrorC "No semicolons directly after 'then'") allspacing action <- readTerm return (condition, action) readElsePart = do g_Else + optional (g_Semi >> parseProblem ErrorC "No semicolons directly after 'else'") allspacing readTerm @@ -885,7 +890,7 @@ tryWordToken s t = tryParseWordToken (string s) t `thenSkip` spacing tryParseWordToken parser t = try $ do id <- getNextId parser - lookAhead (eof <|> disregard whitespace) + lookAhead (keywordSeparator) return $ t id g_AND_IF = tryToken "&&" T_AND_IF @@ -924,6 +929,8 @@ g_Semi = do notFollowedBy g_DSEMI tryToken ";" T_Semi +keywordSeparator = eof <|> disregard allspacing <|> (disregard $ oneOf ";()") + readKeyword = choice [ g_Then, g_Else, g_Elif, g_Fi, g_Do, g_Done, g_Esac, g_Rbrace, g_Rparen, g_DSEMI ] ifParse p t f = do