mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-07 22:38:50 +08:00
Added extglob support
This commit is contained in:
@@ -456,7 +456,11 @@ readNormalWord = do
|
||||
x <- many1 readNormalWordPart
|
||||
return $ T_NormalWord id x
|
||||
|
||||
readNormalWordPart = readSingleQuoted <|> readDoubleQuoted <|> readDollar <|> readBraced <|> readBackTicked <|> (readNormalLiteral)
|
||||
readNormalWordPart = readSingleQuoted <|> readDoubleQuoted <|> readExtglob <|> readDollar <|> readBraced <|> readBackTicked <|> (readNormalLiteral)
|
||||
readSpacePart = do
|
||||
id <- getNextId
|
||||
x <- many1 whitespace
|
||||
return $ T_Literal id x
|
||||
|
||||
prop_readSingleQuoted = isOk readSingleQuoted "'foo bar'"
|
||||
prop_readSingleQuoted2 = isWarning readSingleQuoted "'foo bar\\'"
|
||||
@@ -531,7 +535,7 @@ readNormalEscaped = do
|
||||
pos <- getPosition
|
||||
backslash
|
||||
do
|
||||
next <- (quotable <|> oneOf "?*[]")
|
||||
next <- (quotable <|> oneOf "?*@!+[]")
|
||||
return $ if next == '\n' then "" else [next]
|
||||
<|>
|
||||
do
|
||||
@@ -539,6 +543,25 @@ readNormalEscaped = do
|
||||
parseNoteAt pos WarningC $ "Did you mean \"$(printf \"\\" ++ [next] ++ "\")\"? The shell just ignores the \\ here."
|
||||
return [next]
|
||||
|
||||
|
||||
prop_readExtglob1 = isOk readExtglob "!(*.mp3)"
|
||||
prop_readExtglob2 = isOk readExtglob "!(*.mp3|*.wmv)"
|
||||
prop_readExtglob4 = isOk readExtglob "+(foo \\) bar)"
|
||||
prop_readExtglob5 = isOk readExtglob "+(!(foo *(bar)))"
|
||||
readExtglob = try $ do
|
||||
id <- getNextId
|
||||
c <- oneOf "?*@!+"
|
||||
char '('
|
||||
contents <- readExtglobPart `sepBy` (char '|')
|
||||
char ')'
|
||||
return $ T_Extglob id [c] contents
|
||||
|
||||
readExtglobPart = do
|
||||
id <- getNextId
|
||||
x <- many1 (readNormalWordPart <|> readSpacePart)
|
||||
return $ T_NormalWord id x
|
||||
|
||||
|
||||
readSingleEscaped = do
|
||||
s <- backslash
|
||||
let attempt level p msg = do { try $ parseNote level msg; x <- p; return [s,x]; }
|
||||
|
Reference in New Issue
Block a user