Use syntactic sugar instead of building lists by hand

This commit is contained in:
Joseph C. Sible 2020-12-28 17:55:54 -05:00
parent dfbcc9595e
commit 8480563672
3 changed files with 5 additions and 5 deletions

View File

@ -177,7 +177,7 @@ getOpts (gnu, arbitraryLongOpts) string longopts args = process args
process [] = return [] process [] = return []
process (token:rest) = do process (token:rest) = do
case getLiteralStringDef "\0" token of case getLiteralStringDef "\0" token of
'-':'-':[] -> return $ listToArgs rest "--" -> return $ listToArgs rest
'-':'-':word -> do '-':'-':word -> do
let (name, arg) = span (/= '=') word let (name, arg) = span (/= '=') word
needsArg <- needsArg <-

View File

@ -394,7 +394,7 @@ prop_checkAssignAteCommand4 = verifyNot checkAssignAteCommand "A=foo ls -l"
prop_checkAssignAteCommand5 = verify checkAssignAteCommand "PAGER=cat grep bar" prop_checkAssignAteCommand5 = verify checkAssignAteCommand "PAGER=cat grep bar"
prop_checkAssignAteCommand6 = verifyNot checkAssignAteCommand "PAGER=\"cat\" grep bar" prop_checkAssignAteCommand6 = verifyNot checkAssignAteCommand "PAGER=\"cat\" grep bar"
prop_checkAssignAteCommand7 = verify checkAssignAteCommand "here=pwd" prop_checkAssignAteCommand7 = verify checkAssignAteCommand "here=pwd"
checkAssignAteCommand _ (T_SimpleCommand id (T_Assignment _ _ _ _ assignmentTerm:[]) list) = checkAssignAteCommand _ (T_SimpleCommand id [T_Assignment _ _ _ _ assignmentTerm] list) =
-- Check if first word is intended as an argument (flag or glob). -- Check if first word is intended as an argument (flag or glob).
if firstWordIsArg list if firstWordIsArg list
then then
@ -426,7 +426,7 @@ checkArithmeticOpCommand _ _ = return ()
prop_checkWrongArit = verify checkWrongArithmeticAssignment "i=i+1" prop_checkWrongArit = verify checkWrongArithmeticAssignment "i=i+1"
prop_checkWrongArit2 = verify checkWrongArithmeticAssignment "n=2; i=n*2" prop_checkWrongArit2 = verify checkWrongArithmeticAssignment "n=2; i=n*2"
checkWrongArithmeticAssignment params (T_SimpleCommand id (T_Assignment _ _ _ _ val:[]) []) = checkWrongArithmeticAssignment params (T_SimpleCommand id [T_Assignment _ _ _ _ val] []) =
sequence_ $ do sequence_ $ do
str <- getNormalString val str <- getNormalString val
match <- matchRegex regex str match <- matchRegex regex str
@ -2844,7 +2844,7 @@ checkTestArgumentSplitting params t =
then then
-- Ksh appears to stop processing after unrecognized tokens, so operators -- Ksh appears to stop processing after unrecognized tokens, so operators
-- will effectively work with globs, but only the first match. -- will effectively work with globs, but only the first match.
when (op `elem` ['-':c:[] | c <- "bcdfgkprsuwxLhNOGRS" ]) $ when (op `elem` [['-', c] | c <- "bcdfgkprsuwxLhNOGRS" ]) $
warn (getId token) 2245 $ warn (getId token) 2245 $
op ++ " only applies to the first expansion of this glob. Use a loop to check any/all." op ++ " only applies to the first expansion of this glob. Use a loop to check any/all."
else else

View File

@ -916,7 +916,7 @@ checkWhileGetoptsCase = CommandCheck (Exactly "getopts") f
fromGlob t = fromGlob t =
case t of case t of
T_Glob _ ('[':c:']':[]) -> return [c] T_Glob _ ['[', c, ']'] -> return [c]
T_Glob _ "*" -> return "*" T_Glob _ "*" -> return "*"
T_Glob _ "?" -> return "?" T_Glob _ "?" -> return "?"
_ -> Nothing _ -> Nothing