Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bang as a valid char for function names #3108

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/ShellCheck/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ singleQuote = char '\''
doubleQuote = char '"'
variableStart = upper <|> lower <|> oneOf "_"
variableChars = upper <|> lower <|> digit <|> oneOf "_"
-- Chars to allow in function names
functionChars = variableChars <|> oneOf ":+?-./^@,"
-- Chars to allow function names to start with
functionStartChars = variableChars <|> oneOf ":+?-./^@,"
-- Chars to allow inside function names
functionChars = variableChars <|> oneOf "#:+?-./^@,"
-- Chars to allow function names to start with, using the 'function' keyword
extendedFunctionStartChars = functionStartChars <|> oneOf "[]*=!"
-- Chars to allow in functions using the 'function' keyword
extendedFunctionChars = functionChars <|> oneOf "[]*=!"
extendedFunctionChars = extendedFunctionStartChars <|> oneOf "[]*=!"
specialVariable = oneOf (concat specialVariables)
paramSubSpecialChars = oneOf "/:+-=%"
quotableChars = "|&;<>()\\ '\t\n\r\xA0" ++ doubleQuotableChars
Expand Down Expand Up @@ -2768,7 +2772,7 @@ readFunctionDefinition = called "function" $ do
string "function"
whitespace
spacing
name <- many1 extendedFunctionChars
name <- (:) <$> extendedFunctionStartChars <*> many extendedFunctionChars
spaces <- spacing
hasParens <- wasIncluded readParens
when (not hasParens && null spaces) $
Expand All @@ -2777,7 +2781,7 @@ readFunctionDefinition = called "function" $ do
return $ \id -> T_Function id (FunctionKeyword True) (FunctionParentheses hasParens) name

readWithoutFunction = try $ do
name <- many1 functionChars
name <- (:) <$> functionStartChars <*> many functionChars
guard $ name /= "time" -- Interferes with time ( foo )
spacing
readParens
Expand Down