on master help sign in
clean up the error message when there's nothing after an operator

Relevant to https://github.com/elm/error-message-catalog/issues/248

commitc0e858324de22e7db3b781ca9a68592073de4d1c authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 25 Jul 2019, 16:40 (7 years ago) parent4b6e598
1 file changed+30−15
compiler/src/Reporting/Error/Syntax.hs+30−15
compiler/src/Reporting/Error/Syntax.hs+30−15
@@ -2340,25 +2340,40 @@ toExprReport source context expr startRow startCol =
23402340 )
23412341
23422342 OperatorRight op row col ->
2343− let region = toRegion row col in
2343+ let
2344+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2345+ region = toRegion row col
2346+ isMath = elem op ["-","+","*","/","^"]
2347+ in
23442348 Report.Report "MISSING EXPRESSION" region [] $
2345− Code.toSnippet source region Nothing
2349+ Code.toSnippet source surroundings (Just region)
23462350 (
23472351 D.reflow $
2348− "I was expecting to see an expression after this " ++ Name.toChars op ++ " operator:"
2352+ "I just saw a " ++ Name.toChars op ++ " "
2353+ ++ (if isMath then "sign" else "operator")
2354+ ++ ", so I am getting stuck here:"
23492355 ,
2350− D.stack
2351− [ D.fillSep $
2352− ["You","can","just","put","anything","for","now,","like"
2353− ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
2354− ,"Once","there","is","something","there,","I","can","probably"
2355− ,"give","a","more","specific","hint!"
2356− ]
2357− , D.toSimpleNote $
2358− "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
2359− \ Or if I run into operators in unexpected spots. Point is, there are a\
2360− \ couple ways I can get confused and give sort of weird advice!"
2361− ]
2356+ if isMath then
2357+ D.fillSep
2358+ ["I","was","expecting","to","see","an","expression","next."
2359+ ,"Something","like",D.dullyellow "42","or",D.dullyellow "1000"
2360+ ,"that","makes","sense","with","a",D.fromName op,"sign."
2361+ ]
2362+ else if op == "&&" || op == "||" then
2363+ D.fillSep
2364+ ["I","was","expecting","to","see","an","expression","next."
2365+ ,"Something","like",D.dullyellow "True","or",D.dullyellow "False"
2366+ ,"that","makes","sense","with","boolean","logic."
2367+ ]
2368+ else if op == "|>" then
2369+ D.reflow $
2370+ "I was expecting to see a function next."
2371+ else if op == "<|" then
2372+ D.reflow $
2373+ "I was expecting to see an argument next."
2374+ else
2375+ D.reflow $
2376+ "I was expecting to see an expression next."
23622377 )
23632378
23642379 OperatorReserved operator row col ->