on master help sign in
Improve DeclStart and PTupleEnd message
commit95fe289038ff7ec9337febbd487e0f800c5f02a2 authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 21 May 2019, 18:14 (7 years ago) parent7c7dabb
1 file changed+66−14
compiler/src/Reporting/Error/Syntax.hs+66−14
compiler/src/Reporting/Error/Syntax.hs+66−14
@@ -1233,7 +1233,7 @@ toDeclarationsReport source decl =
12331233 case decl of
12341234 DeclStart row col ->
12351235 case Code.whatIsNext source row col of
1236− Code.Close term _ ->
1236+ Code.Close term bracket ->
12371237 let
12381238 region = toRegion row col
12391239 in
@@ -1243,7 +1243,7 @@ toDeclarationsReport source decl =
12431243 D.reflow $
12441244 "I was not expecting to see a " ++ term ++ " here:"
12451245 , 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?"
12471247 )
12481248
12491249 Code.Keyword keyword ->
@@ -4492,18 +4492,70 @@ toPTupleReport source context tuple startRow startCol =
44924492 )
44934493
44944494 PTupleEnd row col ->
4495− let
4496− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4497− region = toRegion row col
4498− in
4499− Report.Report "UNFINISHED PARENTHESES" region [] $
4500− Code.toSnippet source surroundings (Just region) $
4501− (
4502− D.reflow $
4503− "I was expecting a closing parenthesis next:"
4504− ,
4505− D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
4506− )
4495+ case Code.whatIsNext source row col of
4496+ Code.Keyword keyword ->
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
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)
4531+ region = toRegion row col
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
4548+ Report.Report "UNFINISHED PARENTHESES" region [] $
4549+ Code.toSnippet source surroundings (Just region) $
4550+ (
4551+ D.reflow $
4552+ "I was partway through parsing a pattern, but I got stuck here:"
4553+ ,
4554+ D.fillSep
4555+ ["I","was","expecting","a","closing","parenthesis","next,","so"
4556+ ,"try","adding","a",D.dullyellow ")","to","see","if","that","helps?"
4557+ ]
4558+ )
45074559
45084560 PTupleExpr pattern row col ->
45094561 toPatternReport source context pattern row col