Added check for 'foo(a,b) {', support 'function foo {'
This commit is contained in:
parent
807e56355d
commit
e2a6ffbea4
|
@ -1044,7 +1044,10 @@ readCaseItem = do
|
||||||
return (pattern, list)
|
return (pattern, list)
|
||||||
|
|
||||||
prop_readFunctionDefinition = isOk readFunctionDefinition "foo() { command foo --lol \"$@\"; }"
|
prop_readFunctionDefinition = isOk readFunctionDefinition "foo() { command foo --lol \"$@\"; }"
|
||||||
|
prop_readFunctionDefinition1 = isOk readFunctionDefinition "foo (){ command foo --lol \"$@\"; }"
|
||||||
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_readFunctionDefinition4 = isWarning readFunctionDefinition "foo(a, b) { true; }"
|
||||||
readFunctionDefinition = do
|
readFunctionDefinition = do
|
||||||
id <- getNextId
|
id <- getNextId
|
||||||
name <- try readFunctionSignature
|
name <- try readFunctionSignature
|
||||||
|
@ -1055,12 +1058,37 @@ readFunctionDefinition = do
|
||||||
|
|
||||||
|
|
||||||
readFunctionSignature = do
|
readFunctionSignature = do
|
||||||
acceptButWarn (string "function" >> linewhitespace >> spacing) InfoC "Drop the keyword 'function'. It's optional in Bash but invalid in other shells."
|
readWithFunction <|> readWithoutFunction
|
||||||
name <- readVariableName
|
where
|
||||||
spacing
|
readWithFunction = do
|
||||||
g_Lparen
|
pos <- getPosition
|
||||||
g_Rparen
|
try $ do
|
||||||
return name
|
string "function"
|
||||||
|
whitespace
|
||||||
|
parseProblemAt pos InfoC "Drop the keyword 'function'. It's optional in Bash but invalid in other shells."
|
||||||
|
spacing
|
||||||
|
name <- readVariableName
|
||||||
|
optional spacing
|
||||||
|
pos <- getPosition
|
||||||
|
readParens <|> do
|
||||||
|
parseProblemAt pos InfoC "Include '()' after the function name (in addition to dropping 'function')."
|
||||||
|
return name
|
||||||
|
|
||||||
|
readWithoutFunction = try $ do
|
||||||
|
name <- readVariableName
|
||||||
|
optional spacing
|
||||||
|
readParens
|
||||||
|
return name
|
||||||
|
|
||||||
|
readParens = do
|
||||||
|
g_Lparen
|
||||||
|
optional spacing
|
||||||
|
g_Rparen <|> do
|
||||||
|
parseProblem ErrorC "Trying to declare parameters? Don't. Use () and refer to params as $1, $2.."
|
||||||
|
anyChar `reluctantlyTill` oneOf "\n){"
|
||||||
|
g_Rparen
|
||||||
|
return ()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
readPattern = (readNormalWord `thenSkip` spacing) `sepBy1` (char '|' `thenSkip` spacing)
|
readPattern = (readNormalWord `thenSkip` spacing) `sepBy1` (char '|' `thenSkip` spacing)
|
||||||
|
|
Loading…
Reference in New Issue