Parse 'else if' correctly, and not like elif. Fixes #1088.
This commit is contained in:
parent
ee997fdec4
commit
5b14dba489
|
@ -2,6 +2,9 @@
|
||||||
### Added
|
### Added
|
||||||
- SC2223: Quote warning specific to `: ${var=value}`
|
- SC2223: Quote warning specific to `: ${var=value}`
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- SC1073: 'else if' is now parsed correctly and not like 'elif'
|
||||||
|
|
||||||
## v0.4.7 - 2017-12-08
|
## v0.4.7 - 2017-12-08
|
||||||
### Added
|
### Added
|
||||||
- Statically linked binaries for Linux and Windows (see README.md)!
|
- Statically linked binaries for Linux and Windows (see README.md)!
|
||||||
|
|
|
@ -2035,7 +2035,7 @@ skipAnnotationAndWarn = optional $ do
|
||||||
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_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"
|
||||||
prop_readIfClause4 = isWarning readIfClause "if false; then true; else if true; then echo lol; fi"
|
prop_readIfClause4 = isWarning readIfClause "if false; then true; else if true; then echo lol; fi; fi"
|
||||||
prop_readIfClause5 = isOk readIfClause "if false; then true; else\nif true; then echo lol; fi; fi"
|
prop_readIfClause5 = isOk readIfClause "if false; then true; else\nif true; then echo lol; fi; fi"
|
||||||
readIfClause = called "if expression" $ do
|
readIfClause = called "if expression" $ do
|
||||||
id <- getNextId
|
id <- getNextId
|
||||||
|
@ -2080,12 +2080,9 @@ readIfPart = do
|
||||||
|
|
||||||
readElifPart = called "elif clause" $ do
|
readElifPart = called "elif clause" $ do
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
correctElif <- elif
|
g_Elif
|
||||||
unless correctElif $
|
|
||||||
parseProblemAt pos ErrorC 1075 "Use 'elif' instead of 'else if' (or put 'if' on new line if nesting)."
|
|
||||||
allspacing
|
allspacing
|
||||||
condition <- readTerm
|
condition <- readTerm
|
||||||
|
|
||||||
ifNextToken (g_Fi <|> g_Elif <|> g_Else) $
|
ifNextToken (g_Fi <|> g_Elif <|> g_Else) $
|
||||||
parseProblemAt pos ErrorC 1049 "Did you forget the 'then' for this 'elif'?"
|
parseProblemAt pos ErrorC 1049 "Did you forget the 'then' for this 'elif'?"
|
||||||
|
|
||||||
|
@ -2095,13 +2092,14 @@ readElifPart = called "elif clause" $ do
|
||||||
verifyNotEmptyIf "then"
|
verifyNotEmptyIf "then"
|
||||||
action <- readTerm
|
action <- readTerm
|
||||||
return (condition, action)
|
return (condition, action)
|
||||||
where
|
|
||||||
elif = (g_Elif >> return True) <|>
|
|
||||||
try (g_Else >> g_If >> return False)
|
|
||||||
|
|
||||||
readElsePart = called "else clause" $ do
|
readElsePart = called "else clause" $ do
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
g_Else
|
g_Else
|
||||||
|
optional $ do
|
||||||
|
try . lookAhead $ g_If
|
||||||
|
parseProblemAt pos ErrorC 1075 "Use 'elif' instead of 'else if' (or put 'if' on new line if nesting)."
|
||||||
|
|
||||||
acceptButWarn g_Semi ErrorC 1053 "Semicolons directly after 'else' are not allowed. Just remove it."
|
acceptButWarn g_Semi ErrorC 1053 "Semicolons directly after 'else' are not allowed. Just remove it."
|
||||||
allspacing
|
allspacing
|
||||||
verifyNotEmptyIf "else"
|
verifyNotEmptyIf "else"
|
||||||
|
@ -2917,7 +2915,7 @@ parseShell env name contents = do
|
||||||
isName _ = False
|
isName _ = False
|
||||||
notesForContext list = zipWith ($) [first, second] $ filter isName list
|
notesForContext list = zipWith ($) [first, second] $ filter isName list
|
||||||
first (ContextName pos str) = ParseNote pos pos ErrorC 1073 $
|
first (ContextName pos str) = ParseNote pos pos ErrorC 1073 $
|
||||||
"Couldn't parse this " ++ str ++ "."
|
"Couldn't parse this " ++ str ++ ". Fix to allow more checks."
|
||||||
second (ContextName pos str) = ParseNote pos pos InfoC 1009 $
|
second (ContextName pos str) = ParseNote pos pos InfoC 1009 $
|
||||||
"The mentioned parser error was in this " ++ str ++ "."
|
"The mentioned parser error was in this " ++ str ++ "."
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue