Warn about extra spaces between ((s in for((;;))

This commit is contained in:
Vidar Holen 2020-06-28 16:01:15 -07:00
parent 12d9c1b76d
commit 739eaadbf5
1 changed files with 14 additions and 2 deletions

View File

@ -2485,19 +2485,31 @@ readForClause = called "for loop" $ do
readArithmetic id <|> readRegular id readArithmetic id <|> readRegular id
where where
readArithmetic id = called "arithmetic for condition" $ do readArithmetic id = called "arithmetic for condition" $ do
try $ string "((" readArithmeticDelimiter '(' "Missing second '(' to start arithmetic for ((;;)) loop"
x <- readArithmeticContents x <- readArithmeticContents
char ';' >> spacing char ';' >> spacing
y <- readArithmeticContents y <- readArithmeticContents
char ';' >> spacing char ';' >> spacing
z <- readArithmeticContents z <- readArithmeticContents
spacing spacing
string "))" readArithmeticDelimiter ')' "Missing second ')' to terminate 'for ((;;))' loop condition"
spacing spacing
optional $ readSequentialSep >> spacing optional $ readSequentialSep >> spacing
group <- readBraced <|> readDoGroup id group <- readBraced <|> readDoGroup id
return $ T_ForArithmetic id x y z group return $ T_ForArithmetic id x y z group
-- For c='(' read "((" and be lenient about spaces
readArithmeticDelimiter c msg = do
char c
startPos <- getPosition
sp <- spacing
endPos <- getPosition
char c <|> do
parseProblemAt startPos ErrorC 1137 msg
fail ""
unless (null sp) $
parseProblemAtWithEnd startPos endPos ErrorC 1138 $ "Remove spaces between " ++ [c,c] ++ " in arithmetic for loop."
readBraced = do readBraced = do
(T_BraceGroup _ list) <- readBraceGroup (T_BraceGroup _ list) <- readBraceGroup
return list return list