From 9dadce96c02152d2995804de0619c7420782852f Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 12 Oct 2014 16:17:03 -0700 Subject: [PATCH] Improve messages for missing 'then' statements. --- ShellCheck/Parser.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index 0411a06..bbd3a1a 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -1483,9 +1483,8 @@ readIfPart = do allspacing condition <- readTerm - optional (do - try . lookAhead $ g_Fi - parseProblemAt pos ErrorC 1049 "Did you forget the 'then' for this 'if'?") + ifNextToken (g_Fi <|> g_Elif) $ + parseProblemAt pos ErrorC 1049 "Did you forget the 'then' for this 'if'?" called "then clause" $ do g_Then `orFail` parseProblem ErrorC 1050 "Expected 'then'." @@ -1504,6 +1503,10 @@ readElifPart = called "elif clause" $ do parseProblemAt pos ErrorC 1075 "Use 'elif' instead of 'else if'." allspacing condition <- readTerm + + ifNextToken (g_Fi <|> g_Elif) $ + parseProblemAt pos ErrorC 1049 "Did you forget the 'then' for this 'elif'?" + g_Then acceptButWarn g_Semi ErrorC 1052 "No semicolons directly after 'then'." allspacing @@ -1522,6 +1525,11 @@ readElsePart = called "else clause" $ do verifyNotEmptyIf "else" readTerm +ifNextToken parser action = + optional $ do + try . lookAhead $ parser + action + prop_readSubshell = isOk readSubshell "( cd /foo; tar cf stuff.tar * )" readSubshell = called "explicit subshell" $ do id <- getNextId