More helpful errors for partial if statements
This commit is contained in:
parent
89b0168254
commit
45d5896cf8
|
@ -851,27 +851,41 @@ prop_readIfClause2 = isWarning readIfClause "if false; then; echo oo; fi"
|
||||||
prop_readIfClause3 = isWarning readIfClause "if false; then true; else; echo lol; fi"
|
prop_readIfClause3 = isWarning readIfClause "if false; then true; else; echo lol; fi"
|
||||||
readIfClause = do
|
readIfClause = do
|
||||||
id <- getNextId
|
id <- getNextId
|
||||||
|
pos <- getPosition
|
||||||
(condition, action) <- readIfPart
|
(condition, action) <- readIfPart
|
||||||
elifs <- many readElifPart
|
elifs <- many readElifPart
|
||||||
elses <- option [] readElsePart
|
elses <- option [] readElsePart
|
||||||
g_Fi
|
g_Fi <|> (do
|
||||||
|
eof
|
||||||
|
parseProblemAt pos ErrorC "Can't find 'fi' for this if. Make sure it's preceeded by a ; or \\n"
|
||||||
|
fail "lol"
|
||||||
|
)
|
||||||
return $ T_IfExpression id ((condition, action):elifs) elses
|
return $ T_IfExpression id ((condition, action):elifs) elses
|
||||||
|
|
||||||
|
checkIfNotSpecial pos key stuff = do
|
||||||
|
eof
|
||||||
|
let f (T_Literal id str) | str == key = parseProblemAt pos ErrorC $ "You need a \\n or ; before '"++ key ++ "' to make it special"
|
||||||
|
f t = return ()
|
||||||
|
mapM (doAnalysis f) stuff
|
||||||
|
fail "lol"
|
||||||
|
|
||||||
readIfPart = do
|
readIfPart = do
|
||||||
g_If
|
g_If
|
||||||
allspacing
|
allspacing
|
||||||
|
pos <- getPosition
|
||||||
condition <- readTerm
|
condition <- readTerm
|
||||||
g_Then
|
g_Then <|> (checkIfNotSpecial pos "then" condition)
|
||||||
acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'"
|
acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'"
|
||||||
allspacing
|
allspacing
|
||||||
action <- readTerm
|
action <- readTerm
|
||||||
return (condition, action)
|
return (condition, action)
|
||||||
|
|
||||||
readElifPart = do
|
readElifPart = do
|
||||||
|
pos <- getPosition
|
||||||
g_Elif
|
g_Elif
|
||||||
allspacing
|
allspacing
|
||||||
condition <- readTerm
|
condition <- readTerm
|
||||||
g_Then
|
g_Then <|> (checkIfNotSpecial pos "then" condition)
|
||||||
acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'"
|
acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'"
|
||||||
allspacing
|
allspacing
|
||||||
action <- readTerm
|
action <- readTerm
|
||||||
|
|
Loading…
Reference in New Issue