From 67f4a0d6eb842829a832580a3b7110f1d6221b67 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 15 Mar 2014 16:08:33 -0700 Subject: [PATCH] Accept and warn about capitalization in keywords. --- ShellCheck/Parser.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index 9fb6fc8..f4bd160 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -1811,16 +1811,24 @@ redirToken c t = try $ do notFollowedBy2 $ char '(' return $ t id -tryWordToken s t = tryParseWordToken (string s) t `thenSkip` spacing -tryParseWordToken parser t = try $ do +tryWordToken s t = tryParseWordToken s t `thenSkip` spacing +tryParseWordToken keyword t = try $ do id <- getNextId - parser + str <- anycaseString keyword optional (do try . lookAhead $ char '[' parseProblem ErrorC 1069 "You need a space before the [.") try $ lookAhead (keywordSeparator) + when (str /= keyword) $ + parseProblem ErrorC 1081 $ + "Scripts are case sensitive. Use '" ++ keyword ++ "', not '" ++ str ++ "'." return $ t id +anycaseString str = + mapM anycaseChar str + where + anycaseChar c = char (toLower c) <|> char (toUpper c) + g_AND_IF = tryToken "&&" T_AND_IF g_OR_IF = tryToken "||" T_OR_IF g_DSEMI = tryToken ";;" T_DSEMI