From a8ff7a02fd6ea4cf9f8d57eedae939b7fc445800 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 22 Nov 2014 10:09:19 -0800 Subject: [PATCH] Fix $10 warning triggering for $?!, and also warn about $arr[index]. --- ShellCheck/Parser.hs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index f5044c1..82bf21e 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -1121,23 +1121,33 @@ readDollarExpansion = called "command expansion" $ do return $ T_DollarExpansion id cmds prop_readDollarVariable = isOk readDollarVariable "$@" +prop_readDollarVariable2 = isOk (readDollarVariable >> anyChar) "$?!" +prop_readDollarVariable3 = isWarning (readDollarVariable >> anyChar) "$10" +prop_readDollarVariable4 = isWarning (readDollarVariable >> string "[@]") "$arr[@]" + readDollarVariable = do id <- getNextId + pos <- getPosition + let singleCharred p = do n <- p value <- wrap [n] - return (T_DollarBraced id value) `attempting` do - pos <- getPosition - num <- lookAhead $ many1 p - parseNoteAt pos ErrorC 1037 $ "$" ++ (n:num) ++ " is equivalent to ${" ++ [n] ++ "}"++ num ++"." + return (T_DollarBraced id value) + + let positional = do + value <- singleCharred digit + return value `attempting` do + lookAhead digit + parseNoteAt pos ErrorC 1037 "Braces are required for positionals over 9, e.g. ${10}." - let positional = singleCharred digit let special = singleCharred specialVariable let regular = do name <- readVariableName value <- wrap name - return $ T_DollarBraced id value + return (T_DollarBraced id value) `attempting` do + lookAhead $ void (string "[@]") <|> void (string "[*]") <|> void readArrayIndex + parseNoteAt pos ErrorC 1087 "Braces are required when expanding arrays, as in ${array[idx]}." try $ char '$' >> (positional <|> special <|> regular)