From 0d504f44d9a30ddbe97b541385a24a4178f17876 Mon Sep 17 00:00:00 2001 From: Adrian Fluturel Date: Tue, 31 Dec 2024 03:40:47 +0100 Subject: [PATCH 1/3] Add bang as a valid char for function names --- src/ShellCheck/Parser.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index 9628b2ea5..f1ff26ab2 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -67,7 +67,7 @@ doubleQuote = char '"' variableStart = upper <|> lower <|> oneOf "_" variableChars = upper <|> lower <|> digit <|> oneOf "_" -- Chars to allow in function names -functionChars = variableChars <|> oneOf ":+?-./^@," +functionChars = variableChars <|> oneOf "#:+?-./^@," -- Chars to allow in functions using the 'function' keyword extendedFunctionChars = functionChars <|> oneOf "[]*=!" specialVariable = oneOf (concat specialVariables) From 34b03040d9fdf59bf5e056336235456455e4aa62 Mon Sep 17 00:00:00 2001 From: Adrian Fluturel Date: Tue, 31 Dec 2024 04:48:19 +0100 Subject: [PATCH 2/3] Allow pound symbol only inside the function name --- src/ShellCheck/Parser.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index f1ff26ab2..17107ba8b 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -66,7 +66,9 @@ singleQuote = char '\'' doubleQuote = char '"' variableStart = upper <|> lower <|> oneOf "_" variableChars = upper <|> lower <|> digit <|> oneOf "_" --- Chars to allow in function names +-- Chars to allow function names to start with +functionStartChars = variableChars <|> oneOf ":+?-./^@," +-- Chars to allow inside function names functionChars = variableChars <|> oneOf "#:+?-./^@," -- Chars to allow in functions using the 'function' keyword extendedFunctionChars = functionChars <|> oneOf "[]*=!" @@ -2768,7 +2770,7 @@ readFunctionDefinition = called "function" $ do string "function" whitespace spacing - name <- many1 extendedFunctionChars + name <- (:) <$> functionStartChars <*> many extendedFunctionChars spaces <- spacing hasParens <- wasIncluded readParens when (not hasParens && null spaces) $ @@ -2777,7 +2779,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 From ad1d5fa64fcae9da6043810aab9a716eda464161 Mon Sep 17 00:00:00 2001 From: Adrian Fluturel Date: Tue, 31 Dec 2024 05:01:18 +0100 Subject: [PATCH 3/3] Fix extendedFunction definition --- src/ShellCheck/Parser.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index 17107ba8b..d884a7ba4 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -70,8 +70,10 @@ variableChars = upper <|> lower <|> digit <|> oneOf "_" 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 @@ -2770,7 +2772,7 @@ readFunctionDefinition = called "function" $ do string "function" whitespace spacing - name <- (:) <$> functionStartChars <*> many extendedFunctionChars + name <- (:) <$> extendedFunctionStartChars <*> many extendedFunctionChars spaces <- spacing hasParens <- wasIncluded readParens when (not hasParens && null spaces) $