Modernize getting mapfile array name
This commit is contained in:
parent
3ef1175566
commit
e779aedac3
|
@ -2228,7 +2228,9 @@ prop_checkUnassignedReferences37= verifyNotTree checkUnassignedReferences "var=h
|
||||||
prop_checkUnassignedReferences38= verifyTree (checkUnassignedReferences' True) "echo $VAR"
|
prop_checkUnassignedReferences38= verifyTree (checkUnassignedReferences' True) "echo $VAR"
|
||||||
prop_checkUnassignedReferences39= verifyNotTree checkUnassignedReferences "builtin export var=4; echo $var"
|
prop_checkUnassignedReferences39= verifyNotTree checkUnassignedReferences "builtin export var=4; echo $var"
|
||||||
prop_checkUnassignedReferences40= verifyNotTree checkUnassignedReferences ": ${foo=bar}"
|
prop_checkUnassignedReferences40= verifyNotTree checkUnassignedReferences ": ${foo=bar}"
|
||||||
prop_checkUnassignedReferences41= verifyNotTree checkUnassignedReferences "mapfile -t files <(cat); echo \"${files[@]}\""
|
prop_checkUnassignedReferences41= verifyNotTree checkUnassignedReferences "mapfile -t files 123; echo \"${files[@]}\""
|
||||||
|
prop_checkUnassignedReferences42= verifyNotTree checkUnassignedReferences "mapfile files -t; echo \"${files[@]}\""
|
||||||
|
prop_checkUnassignedReferences43= verifyNotTree checkUnassignedReferences "mapfile --future files; echo \"${files[@]}\""
|
||||||
|
|
||||||
checkUnassignedReferences = checkUnassignedReferences' False
|
checkUnassignedReferences = checkUnassignedReferences' False
|
||||||
checkUnassignedReferences' includeGlobals params t = warnings
|
checkUnassignedReferences' includeGlobals params t = warnings
|
||||||
|
|
|
@ -658,17 +658,30 @@ getModifiedVariableCommand base@(T_SimpleCommand id cmdPrefix (T_NormalWord _ (T
|
||||||
f [] = fail "not found"
|
f [] = fail "not found"
|
||||||
|
|
||||||
-- mapfile has some curious syntax allowing flags plus 0..n variable names
|
-- mapfile has some curious syntax allowing flags plus 0..n variable names
|
||||||
-- where only the first non-option one is used if any. Here we cheat and
|
-- where only the first non-option one is used if any.
|
||||||
-- just get the last one, if it's a variable name, and omitting process
|
getMapfileArray base rest = parseArgs `mplus` fallback
|
||||||
-- substitions.
|
where
|
||||||
getMapfileArray base arguments = do
|
parseArgs :: Maybe (Token, Token, String, DataType)
|
||||||
lastArg <- listToMaybe (filter notProcSub $ reverse arguments)
|
parseArgs = do
|
||||||
name <- getLiteralString lastArg
|
args <- getGnuOpts "d:n:O:s:u:C:c:t" base
|
||||||
guard $ isVariableName name
|
let names = map snd $ filter (\(x,y) -> null x) args
|
||||||
return (base, lastArg, name, DataArray SourceExternal)
|
if null names
|
||||||
|
then
|
||||||
notProcSub (T_NormalWord _ (T_ProcSub{} :_)) = False
|
return (base, base, "MAPFILE", DataArray SourceExternal)
|
||||||
notProcSub _ = True
|
else do
|
||||||
|
first <- listToMaybe names
|
||||||
|
name <- getLiteralString first
|
||||||
|
guard $ isVariableName name
|
||||||
|
return (base, first, name, DataArray SourceExternal)
|
||||||
|
-- If arg parsing fails (due to bad or new flags), get the last variable name
|
||||||
|
fallback :: Maybe (Token, Token, String, DataType)
|
||||||
|
fallback = do
|
||||||
|
(name, token) <- listToMaybe . mapMaybe f $ reverse rest
|
||||||
|
return (base, token, name, DataArray SourceExternal)
|
||||||
|
f arg = do
|
||||||
|
name <- getLiteralString arg
|
||||||
|
guard $ isVariableName name
|
||||||
|
return (name, arg)
|
||||||
|
|
||||||
-- get all the array variables used in read, e.g. read -a arr
|
-- get all the array variables used in read, e.g. read -a arr
|
||||||
getReadArrayVariables args =
|
getReadArrayVariables args =
|
||||||
|
|
Loading…
Reference in New Issue