mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-11 02:02:54 +08:00
Even more robust then/fi/do/done feedback
This commit is contained in:
@@ -898,13 +898,17 @@ readIfClause = do
|
|||||||
return $ T_IfExpression id ((condition, action):elifs) elses
|
return $ T_IfExpression id ((condition, action):elifs) elses
|
||||||
|
|
||||||
readIfPart = do
|
readIfPart = do
|
||||||
|
pos <- getPosition
|
||||||
g_If
|
g_If
|
||||||
allspacing
|
allspacing
|
||||||
pos <- getPosition
|
|
||||||
condition <- readTerm
|
condition <- readTerm
|
||||||
g_Then `attempting` (do
|
|
||||||
try . lookAhead $ g_Do
|
optional (do
|
||||||
parseProblem ErrorC "Perhaps you meant 'then'?")
|
try . lookAhead $ g_Fi
|
||||||
|
parseProblemAt pos ErrorC "Did you forget the 'then' for this 'if'?")
|
||||||
|
|
||||||
|
g_Then `orFail` parseProblem ErrorC "Expected 'then'."
|
||||||
|
|
||||||
acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'."
|
acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'."
|
||||||
allspacing
|
allspacing
|
||||||
action <- readTerm
|
action <- readTerm
|
||||||
@@ -949,30 +953,28 @@ readBraceGroup = do
|
|||||||
|
|
||||||
prop_readWhileClause = isOk readWhileClause "while [[ -e foo ]]; do sleep 1; done"
|
prop_readWhileClause = isOk readWhileClause "while [[ -e foo ]]; do sleep 1; done"
|
||||||
readWhileClause = do
|
readWhileClause = do
|
||||||
(T_While id) <- g_While
|
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
|
(T_While id) <- g_While
|
||||||
condition <- readTerm
|
condition <- readTerm
|
||||||
return () `attempting` (do
|
statements <- readDoGroup pos
|
||||||
eof
|
|
||||||
parseProblemAt pos ErrorC "Condition missing 'do'. Did you forget it or the ; or \\n before it?"
|
|
||||||
)
|
|
||||||
statements <- readDoGroup
|
|
||||||
return $ T_WhileExpression id condition statements
|
return $ T_WhileExpression id condition statements
|
||||||
|
|
||||||
prop_readUntilClause = isOk readUntilClause "until kill -0 $PID; do sleep 1; done"
|
prop_readUntilClause = isOk readUntilClause "until kill -0 $PID; do sleep 1; done"
|
||||||
readUntilClause = do
|
readUntilClause = do
|
||||||
|
pos <- getPosition
|
||||||
(T_Until id) <- g_Until
|
(T_Until id) <- g_Until
|
||||||
condition <- readTerm
|
condition <- readTerm
|
||||||
statements <- readDoGroup
|
statements <- readDoGroup pos
|
||||||
return $ T_UntilExpression id condition statements
|
return $ T_UntilExpression id condition statements
|
||||||
|
|
||||||
readDoGroup = do
|
readDoGroup loopPos = do
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
optional (do
|
optional (do
|
||||||
try . lookAhead $ g_Then
|
try . lookAhead $ g_Done
|
||||||
parseProblem ErrorC "Perhaps you meant 'do'.")
|
parseProblemAt loopPos ErrorC "Did you forget the 'do' for this loop?")
|
||||||
|
|
||||||
|
g_Do `orFail` parseProblem ErrorC "Expected 'do'."
|
||||||
|
|
||||||
g_Do
|
|
||||||
acceptButWarn g_Semi ErrorC "No semicolons directly after 'do'."
|
acceptButWarn g_Semi ErrorC "No semicolons directly after 'do'."
|
||||||
allspacing
|
allspacing
|
||||||
|
|
||||||
@@ -986,16 +988,13 @@ readDoGroup = do
|
|||||||
prop_readForClause = isOk readForClause "for f in *; do rm \"$f\"; done"
|
prop_readForClause = isOk readForClause "for f in *; do rm \"$f\"; done"
|
||||||
prop_readForClause3 = isOk readForClause "for f; do foo; done"
|
prop_readForClause3 = isOk readForClause "for f; do foo; done"
|
||||||
readForClause = do
|
readForClause = do
|
||||||
|
pos <- getPosition
|
||||||
(T_For id) <- g_For
|
(T_For id) <- g_For
|
||||||
spacing
|
spacing
|
||||||
name <- readVariableName
|
name <- readVariableName
|
||||||
spacing
|
spacing
|
||||||
values <- readInClause <|> (readSequentialSep >> return [])
|
values <- readInClause <|> (readSequentialSep >> return [])
|
||||||
group <- readDoGroup <|> (
|
group <- readDoGroup pos
|
||||||
allspacing >>
|
|
||||||
eof >>
|
|
||||||
parseProblem ErrorC "Missing 'do'." >>
|
|
||||||
return [])
|
|
||||||
return $ T_ForIn id name values group
|
return $ T_ForIn id name values group
|
||||||
|
|
||||||
readInClause = do
|
readInClause = do
|
||||||
|
Reference in New Issue
Block a user