Allow :+- in function names. :(){ :|:;};:, anyone?

This commit is contained in:
Vidar Holen 2013-08-03 20:22:32 -07:00
parent d0caa1e1df
commit 07b1fd6f44
1 changed files with 6 additions and 2 deletions

View File

@ -41,6 +41,7 @@ singleQuote = char '\''
doubleQuote = char '"' doubleQuote = char '"'
variableStart = upper <|> lower <|> oneOf "_" variableStart = upper <|> lower <|> oneOf "_"
variableChars = upper <|> lower <|> digit <|> oneOf "_" variableChars = upper <|> lower <|> digit <|> oneOf "_"
functionChars = variableChars <|> oneOf ":+-"
specialVariable = oneOf "@*#?-$!" specialVariable = oneOf "@*#?-$!"
tokenDelimiter = oneOf "&|;<> \t\n\r" <|> nbsp tokenDelimiter = oneOf "&|;<> \t\n\r" <|> nbsp
quotable = oneOf "|&;<>()$`\\ \"'\t\n\r" <|> nbsp quotable = oneOf "|&;<>()$`\\ \"'\t\n\r" <|> nbsp
@ -1402,6 +1403,7 @@ prop_readFunctionDefinition1 = isOk readFunctionDefinition "foo (){ command fo
prop_readFunctionDefinition2 = isWarning readFunctionDefinition "function foo() { command foo --lol \"$@\"; }" prop_readFunctionDefinition2 = isWarning readFunctionDefinition "function foo() { command foo --lol \"$@\"; }"
prop_readFunctionDefinition3 = isWarning readFunctionDefinition "function foo { lol; }" prop_readFunctionDefinition3 = isWarning readFunctionDefinition "function foo { lol; }"
prop_readFunctionDefinition4 = isWarning readFunctionDefinition "foo(a, b) { true; }" prop_readFunctionDefinition4 = isWarning readFunctionDefinition "foo(a, b) { true; }"
prop_readFunctionDefinition5 = isOk readFunctionDefinition ":(){ :|:;}"
readFunctionDefinition = called "function" $ do readFunctionDefinition = called "function" $ do
id <- getNextId id <- getNextId
name <- try readFunctionSignature name <- try readFunctionSignature
@ -1421,7 +1423,7 @@ readFunctionSignature = do
whitespace whitespace
parseProblemAt pos InfoC "Drop the keyword 'function'. It's optional in Bash but invalid in other shells." parseProblemAt pos InfoC "Drop the keyword 'function'. It's optional in Bash but invalid in other shells."
spacing spacing
name <- readVariableName name <- readFunctionName
optional spacing optional spacing
pos <- getPosition pos <- getPosition
readParens <|> do readParens <|> do
@ -1429,7 +1431,7 @@ readFunctionSignature = do
return name return name
readWithoutFunction = try $ do readWithoutFunction = try $ do
name <- readVariableName name <- readFunctionName
optional spacing optional spacing
readParens readParens
return name return name
@ -1443,6 +1445,8 @@ readFunctionSignature = do
g_Rparen g_Rparen
return () return ()
readFunctionName = many1 functionChars
readPattern = (readNormalWord `thenSkip` spacing) `sepBy1` (char '|' `thenSkip` spacing) readPattern = (readNormalWord `thenSkip` spacing) `sepBy1` (char '|' `thenSkip` spacing)