From 74ea5eaeec7f03724f4023bc8dec73651c3e1880 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 25 Jan 2014 14:12:31 -0800 Subject: [PATCH] Parse but warn about "else if" --- ShellCheck/Parser.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index 932f52d..e998b83 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -1348,6 +1348,8 @@ readCmdWord = do 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" +prop_readIfClause4 = isWarning readIfClause "if false; then true; else if true; then echo lol; fi" +prop_readIfClause5 = isOk readIfClause "if false; then true; else\nif true; then echo lol; fi; fi" readIfClause = called "if expression" $ do id <- getNextId pos <- getPosition @@ -1389,7 +1391,9 @@ readIfPart = do readElifPart = called "elif clause" $ do pos <- getPosition - g_Elif + correctElif <- elif + when (not correctElif) $ + parseProblemAt pos ErrorC 1075 "Use 'elif' instead of 'else if'." allspacing condition <- readTerm g_Then @@ -1398,8 +1402,12 @@ readElifPart = called "elif clause" $ do verifyNotEmptyIf "then" action <- readTerm return (condition, action) + where + elif = (g_Elif >> return True) <|> + (try $ g_Else >> g_If >> return False) readElsePart = called "else clause" $ do + pos <- getPosition g_Else acceptButWarn g_Semi ErrorC 1053 "No semicolons directly after 'else'." allspacing