Added warnings for then;, else;

This commit is contained in:
Vidar Holen 2012-11-03 16:27:17 -07:00
parent 041581b05f
commit 54de7e7e1c
1 changed files with 8 additions and 1 deletions

View File

@ -683,6 +683,8 @@ readCmdWord = do
return f return f
prop_readIfClause = isOk readIfClause "if false; then foo; elif true; then stuff; more stuff; else cows; fi" prop_readIfClause = isOk readIfClause "if false; then foo; elif true; then stuff; more stuff; else cows; fi"
prop_readIfClause2 = isWarning readIfClause "if false; then; echo oo; fi"
prop_readIfClause3 = isWarning readIfClause "if false; then true; else; echo lol fi"
readIfClause = do readIfClause = do
id <- getNextId id <- getNextId
(condition, action) <- readIfPart (condition, action) <- readIfPart
@ -696,6 +698,7 @@ readIfPart = do
allspacing allspacing
condition <- readTerm condition <- readTerm
g_Then g_Then
optional (g_Semi >> parseProblem ErrorC "No semicolons directly after 'then'")
allspacing allspacing
action <- readTerm action <- readTerm
return (condition, action) return (condition, action)
@ -705,12 +708,14 @@ readElifPart = do
allspacing allspacing
condition <- readTerm condition <- readTerm
g_Then g_Then
optional (g_Semi >> parseProblem ErrorC "No semicolons directly after 'then'")
allspacing allspacing
action <- readTerm action <- readTerm
return (condition, action) return (condition, action)
readElsePart = do readElsePart = do
g_Else g_Else
optional (g_Semi >> parseProblem ErrorC "No semicolons directly after 'else'")
allspacing allspacing
readTerm readTerm
@ -885,7 +890,7 @@ tryWordToken s t = tryParseWordToken (string s) t `thenSkip` spacing
tryParseWordToken parser t = try $ do tryParseWordToken parser t = try $ do
id <- getNextId id <- getNextId
parser parser
lookAhead (eof <|> disregard whitespace) lookAhead (keywordSeparator)
return $ t id return $ t id
g_AND_IF = tryToken "&&" T_AND_IF g_AND_IF = tryToken "&&" T_AND_IF
@ -924,6 +929,8 @@ g_Semi = do
notFollowedBy g_DSEMI notFollowedBy g_DSEMI
tryToken ";" T_Semi tryToken ";" T_Semi
keywordSeparator = eof <|> disregard allspacing <|> (disregard $ oneOf ";()")
readKeyword = choice [ g_Then, g_Else, g_Elif, g_Fi, g_Do, g_Done, g_Esac, g_Rbrace, g_Rparen, g_DSEMI ] readKeyword = choice [ g_Then, g_Else, g_Elif, g_Fi, g_Do, g_Done, g_Esac, g_Rbrace, g_Rparen, g_DSEMI ]
ifParse p t f = do ifParse p t f = do