Improved empty then/elif/else clause errors
This commit is contained in:
parent
dd115a6d35
commit
e64698dc78
|
@ -1048,6 +1048,12 @@ readIfClause = called "if expression" $ do
|
||||||
|
|
||||||
return $ T_IfExpression id ((condition, action):elifs) elses
|
return $ T_IfExpression id ((condition, action):elifs) elses
|
||||||
|
|
||||||
|
|
||||||
|
verifyNotEmptyIf s =
|
||||||
|
optional (do
|
||||||
|
emptyPos <- getPosition
|
||||||
|
try . lookAhead $ (g_Fi <|> g_Elif <|> g_Else)
|
||||||
|
parseProblemAt emptyPos ErrorC $ "Can't have empty " ++ s ++ " clauses (use 'true' as a no-op).")
|
||||||
readIfPart = do
|
readIfPart = do
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
g_If
|
g_If
|
||||||
|
@ -1063,11 +1069,7 @@ readIfPart = do
|
||||||
|
|
||||||
acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'."
|
acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'."
|
||||||
allspacing
|
allspacing
|
||||||
|
verifyNotEmptyIf "then"
|
||||||
optional (do
|
|
||||||
emptyPos <- getPosition
|
|
||||||
try . lookAhead $ (g_Fi <|> g_Elif)
|
|
||||||
parseProblemAt emptyPos ErrorC "Can't have empty then clauses (use 'true' as a no-op).")
|
|
||||||
|
|
||||||
action <- readTerm
|
action <- readTerm
|
||||||
return (condition, action)
|
return (condition, action)
|
||||||
|
@ -1080,6 +1082,7 @@ readElifPart = called "elif clause" $ do
|
||||||
g_Then
|
g_Then
|
||||||
acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'."
|
acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'."
|
||||||
allspacing
|
allspacing
|
||||||
|
verifyNotEmptyIf "then"
|
||||||
action <- readTerm
|
action <- readTerm
|
||||||
return (condition, action)
|
return (condition, action)
|
||||||
|
|
||||||
|
@ -1087,6 +1090,7 @@ readElsePart = called "else clause" $ do
|
||||||
g_Else
|
g_Else
|
||||||
acceptButWarn g_Semi ErrorC "No semicolons directly after 'else'."
|
acceptButWarn g_Semi ErrorC "No semicolons directly after 'else'."
|
||||||
allspacing
|
allspacing
|
||||||
|
verifyNotEmptyIf "else"
|
||||||
readTerm
|
readTerm
|
||||||
|
|
||||||
prop_readSubshell = isOk readSubshell "( cd /foo; tar cf stuff.tar * )"
|
prop_readSubshell = isOk readSubshell "( cd /foo; tar cf stuff.tar * )"
|
||||||
|
|
Loading…
Reference in New Issue