on master help sign in
Make errors for primes in variables much more precise
cf107f9Evan Czaplicki
src/Parse/Helpers.hs+15−11
@@ -90,28 +90,32 @@ rLabel = lowVar
90
90
91innerVarChar :: IParser Char
91innerVarChar :: IParser Char
92innerVarChar =
92innerVarChar =
93− choice
94− [ alphaNum
95− , char '_'
96− , char '\'' >> fail Syntax.prime
97− ]
98− <?> "more letters in this name"
93+ alphaNum <|> char '_' <?> "more letters in this name"
99
94
100
95
101makeVar :: IParser Char -> IParser String
96makeVar :: IParser Char -> IParser String
102makeVar firstChar =
97makeVar firstChar =
103 do variable <- (:) <$> firstChar <*> many innerVarChar
98 do variable <- (:) <$> firstChar <*> many innerVarChar
99+ choice
100+ [ do lookAhead (char '\'')
101+ failure (Syntax.prime variable)
104− if variable `elem` reserveds
102+ , if variable `elem` reserveds then
105− then fail (Syntax.keyword variable)
103+ failure (Syntax.keyword variable)
104+ else
106− else return variable
105+ return variable
106+ ]
107
107
108
108
109reserved :: String -> IParser String
109reserved :: String -> IParser String
110reserved word =
110reserved word =
111 expecting ("reserved word `" ++ word ++ "`") $
111 expecting ("reserved word `" ++ word ++ "`") $
112 do string word
112 do string word
113+ choice
114+ [ do lookAhead (char '\'')
115+ failure (Syntax.prime word)
113− notFollowedBy innerVarChar
116+ , do notFollowedBy innerVarChar
114− return word
117+ return word
118+ ]
115
119
116
120
117
121
src/Reporting/Error/Syntax.hs+12−12
@@ -328,15 +328,15 @@ keyword kwd =
328 "KEYWORD=" ++ kwd
328 "KEYWORD=" ++ kwd
329
329
330
330
331−prime :: String
331+prime :: String -> String
332−prime =
332+prime var =
333− "PRIME"
333+ "PRIME=" ++ var
334
334
335
335
336data SpecialMessage
336data SpecialMessage
337 = MsgKeyword String
337 = MsgKeyword String
338+ | MsgPrime String
338 | MsgTab
339 | MsgTab
339− | MsgPrime
340
340
341
341
342extractSpecialMessage :: String -> Maybe SpecialMessage
342extractSpecialMessage :: String -> Maybe SpecialMessage
@@ -344,12 +344,12 @@ extractSpecialMessage message =
344 if List.isPrefixOf "KEYWORD=" message then
344 if List.isPrefixOf "KEYWORD=" message then
345 Just $ MsgKeyword (drop (length "KEYWORD=") message)
345 Just $ MsgKeyword (drop (length "KEYWORD=") message)
346
346
347+ else if List.isPrefixOf "PRIME=" message then
348+ Just $ MsgPrime (drop (length "PRIME=") message)
349+
347 else if tab == message then
350 else if tab == message then
348 Just MsgTab
351 Just MsgTab
349
352
350− else if prime == message then
351− Just MsgPrime
352−
353 else
353 else
354 Nothing
354 Nothing
355
355
@@ -397,16 +397,16 @@ parseErrorReport messages =
397 , Just "Rename it to something else."
397 , Just "Rename it to something else."
398 )
398 )
399
399
400+ Just (MsgPrime var) ->
401+ ( "Ran into a single quote in a variable name. This was removed in 0.18!"
402+ , Just $ "Change it to a number or an underscore, like " ++ var ++ "_ or " ++ var ++ "1"
403+ )
404+
400 Just MsgTab ->
405 Just MsgTab ->
401 ( "A tab character was found, but all whitespace (including indentation) must be spaces not tabs."
406 ( "A tab character was found, but all whitespace (including indentation) must be spaces not tabs."
402 , Just "I am looking for spaces, not tabs."
407 , Just "I am looking for spaces, not tabs."
403 )
408 )
404
409
405− Just MsgPrime ->
406− ( "Ran into a single quote in a variable name. This was removed in 0.18!"
407− , Just "Change it to a number or an underscore: x' => x1"
408− )
409−
410 Nothing ->
410 Nothing ->
411 ( msg
411 ( msg
412 , Nothing
412 , Nothing