on master help sign in
Improve DeclStart and PTupleEnd message
95fe289Evan Czaplicki
compiler/src/Reporting/Error/Syntax.hs+66−14
@@ -1233,7 +1233,7 @@ toDeclarationsReport source decl =
1233 case decl of
1233 case decl of
1234 DeclStart row col ->
1234 DeclStart row col ->
1235 case Code.whatIsNext source row col of
1235 case Code.whatIsNext source row col of
1236− Code.Close term _ ->
1236+ Code.Close term bracket ->
1237 let
1237 let
1238 region = toRegion row col
1238 region = toRegion row col
1239 in
1239 in
@@ -1243,7 +1243,7 @@ toDeclarationsReport source decl =
1243 D.reflow $
1243 D.reflow $
1244 "I was not expecting to see a " ++ term ++ " here:"
1244 "I was not expecting to see a " ++ term ++ " here:"
1245 , D.reflow $
1245 , D.reflow $
1246− "It does not match up with anything. Maybe try deleting it?"
1246+ "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
1247 )
1247 )
1248
1248
1249 Code.Keyword keyword ->
1249 Code.Keyword keyword ->
@@ -4492,18 +4492,70 @@ toPTupleReport source context tuple startRow startCol =
4492 )
4492 )
4493
4493
4494 PTupleEnd row col ->
4494 PTupleEnd row col ->
4495+ case Code.whatIsNext source row col of
4496+ Code.Keyword keyword ->
4495− let
4497+ let
4498+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4499+ region = toKeywordRegion row col keyword
4500+ in
4501+ Report.Report "RESERVED WORD" region [] $
4502+ Code.toSnippet source surroundings (Just region) $
4503+ (
4504+ D.reflow $
4505+ "I ran into a reserved word in this pattern:"
4506+ ,
4507+ D.reflow $
4508+ "The `" ++ keyword ++ "` keyword is reserved. Try using a different name instead!"
4509+ )
4510+
4511+ Code.Operator op ->
4512+ let
4496− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4513+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4514+ region = toKeywordRegion row col op
4515+ in
4516+ Report.Report "UNEXPECTED SYMBOL" region [] $
4517+ Code.toSnippet source surroundings (Just region) $
4518+ (
4519+ D.reflow $
4520+ "I ran into the " ++ op ++ " symbol unexpectedly in this pattern:"
4521+ ,
4522+ D.reflow $
4523+ "Only the :: symbol that works in patterns. It is useful if you\
4524+ \ are pattern matching on lists, trying to get the first element\
4525+ \ off the front. Did you want that instead?"
4526+ )
4527+
4528+ Code.Close term bracket ->
4529+ let
4530+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4497− region = toRegion row col
4531+ region = toRegion row col
4498− in
4532+ in
4533+ Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
4534+ Code.toSnippet source surroundings (Just region) $
4535+ (
4536+ D.reflow $
4537+ "I ran into a an unexpected " ++ term ++ " in this pattern:"
4538+ ,
4539+ D.reflow $
4540+ "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
4541+ )
4542+
4543+ _ ->
4544+ let
4545+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4546+ region = toRegion row col
4547+ in
4499− Report.Report "UNFINISHED PARENTHESES" region [] $
4548+ Report.Report "UNFINISHED PARENTHESES" region [] $
4500− Code.toSnippet source surroundings (Just region) $
4549+ Code.toSnippet source surroundings (Just region) $
4501− (
4550+ (
4502− D.reflow $
4551+ D.reflow $
4552+ "I was partway through parsing a pattern, but I got stuck here:"
4553+ ,
4554+ D.fillSep
4503− "I was expecting a closing parenthesis next:"
4555+ ["I","was","expecting","a","closing","parenthesis","next,","so"
4504− ,
4505− D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
4556+ ,"try","adding","a",D.dullyellow ")","to","see","if","that","helps?"
4557+ ]
4506− )
4558+ )
4507
4559
4508 PTupleExpr pattern row col ->
4560 PTupleExpr pattern row col ->
4509 toPatternReport source context pattern row col
4561 toPatternReport source context pattern row col