on master help sign in
Switch to Code.toSnippet and detect keywords in record fields and lambda args
commit0bdcdd825f0f58ee150c5b35ece1a41ffa04acb9 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 9 May 2019, 11:30 (7 years ago) parent00f1290
1 file changed+206−149
compiler/src/Reporting/Error/Syntax.hs+206−149
compiler/src/Reporting/Error/Syntax.hs+206−149
@@ -39,7 +39,6 @@ module Reporting.Error.Syntax
3939 , Number(..)
4040 --
4141 , Space(..)
42− , Operator(..)
4342 , toReport
4443 )
4544 where
@@ -53,6 +52,7 @@ import Numeric (showHex)
5352
5453import qualified Elm.ModuleName as ModuleName
5554import Parse.Primitives (Row, Col)
55+import Parse.Symbol (BadOperator(..))
5656import qualified Reporting.Annotation as A
5757import qualified Reporting.Doc as D
5858import qualified Reporting.Report as Report
@@ -118,7 +118,7 @@ data Exposing
118118 | ExposingStart Row Col
119119 | ExposingValue Row Col
120120 | ExposingOperator Row Col
121− | ExposingOperatorReserved Operator Row Col
121+ | ExposingOperatorReserved BadOperator Row Col
122122 | ExposingOperatorRightParen Row Col
123123 | ExposingEnd Row Col
124124 --
@@ -229,7 +229,7 @@ data Expr
229229 | Dot Row Col
230230 | Access Row Col
231231 | OperatorRight Name.Name Row Col
232− | OperatorReserved Operator Row Col
232+ | OperatorReserved BadOperator Row Col
233233 --
234234 | Start Row Col
235235 | Char Char Row Col
@@ -262,7 +262,7 @@ data Tuple
262262 | TupleSpace Space Row Col
263263 | TupleEnd Row Col
264264 | TupleOperatorClose Row Col
265− | TupleOperatorReserved Operator Row Col
265+ | TupleOperatorReserved BadOperator Row Col
266266 --
267267 | TupleIndentExpr1 Row Col
268268 | TupleIndentExprN Row Col
@@ -498,14 +498,6 @@ data Space
498498 | EndlessMultiComment
499499
500500
501−data Operator
502− = OpDot
503− | OpPipe
504− | OpArrow
505− | OpEquals
506− | OpHasType
507−
508−
509501
510502-- TO REPORT
511503
@@ -536,7 +528,7 @@ toReport source err =
536528
537529 ModuleNameMismatch expectedName (A.At region actualName) ->
538530 Report.Report "MODULE NAME MISMATCH" region [ModuleName.toChars expectedName] $
539− Report.toCodeSnippet source region Nothing
531+ Code.toSnippet source region Nothing
540532 (
541533 "It looks like this module name is out of sync:"
542534 ,
@@ -575,7 +567,7 @@ toParseErrorReport source modul =
575567 region = toRegion row col
576568 in
577569 Report.Report "EXPECTING END OF FILE" region [] $
578− Report.toCodeSnippet source region Nothing
570+ Code.toSnippet source region Nothing
579571 (
580572 D.reflow $
581573 "I was not expecting to see anything more here:"
@@ -659,7 +651,7 @@ toParseErrorReport source modul =
659651 region = toRegion row col
660652 in
661653 Report.Report "UNFINISHED IMPORT" region [] $
662− Report.toCodeSnippet source region Nothing
654+ Code.toSnippet source region Nothing
663655 (
664656 D.reflow $
665657 "I was parsing an `import` until I got stuck here:"
@@ -683,7 +675,7 @@ toParseErrorReport source modul =
683675 region = toRegion row col
684676 in
685677 Report.Report "BAD INFIX" region [] $
686− Report.toCodeSnippet source region Nothing
678+ Code.toSnippet source region Nothing
687679 (
688680 D.reflow $
689681 "Something went wrong in this infix operator declaration:"
@@ -705,7 +697,7 @@ toSpaceReport source space row col =
705697 region = toRegion row col
706698 in
707699 Report.Report "NO TABS" region [] $
708− Report.toCodeSnippet source region Nothing
700+ Code.toSnippet source region Nothing
709701 (
710702 D.reflow $
711703 "I ran into a tab, but tabs are not allowed in Elm files."
@@ -719,7 +711,7 @@ toSpaceReport source space row col =
719711 region = toWiderRegion row col 2
720712 in
721713 Report.Report "ENDLESS COMMENT" region [] $
722− Report.toCodeSnippet source region Nothing
714+ Code.toSnippet source region Nothing
723715 (
724716 D.reflow $
725717 "I cannot find the end of this multi-line comment:"
@@ -876,7 +868,7 @@ toExprReport source context expr startRow startCol =
876868 Dot row col ->
877869 let region = toRegion row col in
878870 Report.Report "EXPECTING RECORD ACCESSOR" region [] $
879− Report.toCodeSnippet source region Nothing
871+ Code.toSnippet source region Nothing
880872 (
881873 D.reflow $
882874 "I was expecting to see a record accessor here:"
@@ -890,7 +882,7 @@ toExprReport source context expr startRow startCol =
890882 Access row col ->
891883 let region = toRegion row col in
892884 Report.Report "EXPECTING RECORD ACCESSOR" region [] $
893− Report.toCodeSnippet source region Nothing
885+ Code.toSnippet source region Nothing
894886 (
895887 D.reflow $
896888 "I am trying to parse a record accessor here:"
@@ -910,7 +902,7 @@ toExprReport source context expr startRow startCol =
910902 OperatorRight op row col ->
911903 let region = toRegion row col in
912904 Report.Report "MISSING EXPRESSION" region [] $
913− Report.toCodeSnippet source region Nothing
905+ Code.toSnippet source region Nothing
914906 (
915907 D.reflow $
916908 "I was expecting to see an expression after this " ++ Name.toChars op ++ " operator:"
@@ -950,7 +942,7 @@ toExprReport source context expr startRow startCol =
950942 region = toRegion row col
951943 in
952944 Report.Report "MISSING EXPRESSION" region [] $
953− Report.toCodeSnippet source surroundings (Just region)
945+ Code.toSnippet source surroundings (Just region)
954946 (
955947 D.reflow $
956948 "I am partway through parsing " ++ aThing ++ ", but I got stuck here:"
@@ -986,7 +978,7 @@ toExprReport source context expr startRow startCol =
986978 region = toWiderRegion row col 6
987979 in
988980 Report.Report "ENDLESS SHADER" region [] $
989− Report.toCodeSnippet source region Nothing
981+ Code.toSnippet source region Nothing
990982 (
991983 D.reflow "I cannot find the end of this shader:"
992984 ,
@@ -998,7 +990,7 @@ toExprReport source context expr startRow startCol =
998990 region = toRegion row col
999991 in
1000992 Report.Report "SHADER PROBLEM" region [] $
1001− Report.toCodeSnippet source region Nothing
993+ Code.toSnippet source region Nothing
1002994 (
1003995 D.reflow $
1004996 "I ran into a problem while parsing this GLSL block."
@@ -1017,7 +1009,7 @@ toExprReport source context expr startRow startCol =
10171009 region = toRegion row col
10181010 in
10191011 Report.Report "MISSING EXPRESSION" region [] $
1020− Report.toCodeSnippet source surroundings (Just region)
1012+ Code.toSnippet source surroundings (Just region)
10211013 (
10221014 D.reflow $
10231015 "I was expecting to see an expression after this " ++ Name.toChars op ++ " operator:"
@@ -1042,6 +1034,10 @@ toExprReport source context expr startRow startCol =
10421034 error "TODO IndentMoreExpr"
10431035
10441036
1037+
1038+-- CHAR
1039+
1040+
10451041toCharReport :: Code.Source -> Char -> Row -> Col -> Report.Report
10461042toCharReport source char row col =
10471043 case char of
@@ -1050,7 +1046,7 @@ toCharReport source char row col =
10501046 region = toRegion row col
10511047 in
10521048 Report.Report "MISSING SINGLE QUOTE" region [] $
1053− Report.toCodeSnippet source region Nothing
1049+ Code.toSnippet source region Nothing
10541050 (
10551051 D.reflow $
10561052 "I thought I was parsing a character, but I got to the end of\
@@ -1068,7 +1064,7 @@ toCharReport source char row col =
10681064 region = toWiderRegion row col width
10691065 in
10701066 Report.Report "NEEDS DOUBLE QUOTES" region [] $
1071− Report.toCodeSnippet source region Nothing
1067+ Code.toSnippet source region Nothing
10721068 (
10731069 "The following string uses single quotes:"
10741070 ,
@@ -1085,6 +1081,10 @@ toCharReport source char row col =
10851081 )
10861082
10871083
1084+
1085+-- STRING
1086+
1087+
10881088toStringReport :: Code.Source -> String -> Row -> Col -> Report.Report
10891089toStringReport source string row col =
10901090 case string of
@@ -1093,7 +1093,7 @@ toStringReport source string row col =
10931093 region = toRegion row col
10941094 in
10951095 Report.Report "ENDLESS STRING" region [] $
1096− Report.toCodeSnippet source region Nothing
1096+ Code.toSnippet source region Nothing
10971097 (
10981098 D.reflow $
10991099 "I got to the end of the line without seeing the closing double quote:"
@@ -1113,7 +1113,7 @@ toStringReport source string row col =
11131113 region = toWiderRegion row col 3
11141114 in
11151115 Report.Report "ENDLESS STRING" region [] $
1116− Report.toCodeSnippet source region Nothing
1116+ Code.toSnippet source region Nothing
11171117 (
11181118 D.reflow $
11191119 "I cannot find the end of this multi-line string:"
@@ -1128,6 +1128,10 @@ toStringReport source string row col =
11281128 toEscapeReport source escape row col
11291129
11301130
1131+
1132+-- ESCAPES
1133+
1134+
11311135toEscapeReport :: Code.Source -> Escape -> Row -> Col -> Report.Report
11321136toEscapeReport source escape row col =
11331137 case escape of
@@ -1136,7 +1140,7 @@ toEscapeReport source escape row col =
11361140 region = toWiderRegion row col 2
11371141 in
11381142 Report.Report "UNKNOWN ESCAPE" region [] $
1139− Report.toCodeSnippet source region Nothing
1143+ Code.toSnippet source region Nothing
11401144 (
11411145 D.reflow $
11421146 "Backslashes always start escaped characters, but I do not recognize this one:"
@@ -1167,7 +1171,7 @@ toEscapeReport source escape row col =
11671171 region = toWiderRegion row col width
11681172 in
11691173 Report.Report "BAD UNICODE ESCAPE" region [] $
1170− Report.toCodeSnippet source region Nothing
1174+ Code.toSnippet source region Nothing
11711175 (
11721176 D.reflow $
11731177 "I ran into an invalid Unicode escape:"
@@ -1191,7 +1195,7 @@ toEscapeReport source escape row col =
11911195 region = toWiderRegion row col width
11921196 in
11931197 Report.Report "BAD UNICODE ESCAPE" region [] $
1194− Report.toCodeSnippet source region Nothing
1198+ Code.toSnippet source region Nothing
11951199 (
11961200 D.reflow $
11971201 "This is not a valid code point:"
@@ -1205,7 +1209,7 @@ toEscapeReport source escape row col =
12051209 region = toWiderRegion row col width
12061210 in
12071211 Report.Report "BAD UNICODE ESCAPE" region [] $
1208− Report.toCodeSnippet source region Nothing $
1212+ Code.toSnippet source region Nothing $
12091213 if numDigits < 4 then
12101214 (
12111215 D.reflow $
@@ -1232,6 +1236,10 @@ toEscapeReport source escape row col =
12321236 )
12331237
12341238
1239+
1240+-- NUMBERS
1241+
1242+
12351243toNumberReport :: Code.Source -> Number -> Row -> Col -> Report.Report
12361244toNumberReport source number row col =
12371245 let
@@ -1240,7 +1248,7 @@ toNumberReport source number row col =
12401248 case number of
12411249 NumberEnd ->
12421250 Report.Report "WEIRD NUMBER" region [] $
1243− Report.toCodeSnippet source region Nothing
1251+ Code.toSnippet source region Nothing
12441252 (
12451253 D.reflow $
12461254 "I thought I was reading a number, but I ran into some weird stuff here:"
@@ -1256,7 +1264,7 @@ toNumberReport source number row col =
12561264
12571265 NumberDot int ->
12581266 Report.Report "WEIRD NUMBER" region [] $
1259− Report.toCodeSnippet source region Nothing
1267+ Code.toSnippet source region Nothing
12601268 (
12611269 D.reflow $
12621270 "Numbers cannot end with a dot like this:"
@@ -1270,7 +1278,7 @@ toNumberReport source number row col =
12701278
12711279 NumberHexDigit ->
12721280 Report.Report "WEIRD HEXIDECIMAL" region [] $
1273− Report.toCodeSnippet source region Nothing
1281+ Code.toSnippet source region Nothing
12741282 (
12751283 D.reflow $
12761284 "I thought I was reading a hexidecimal number until I got here:"
@@ -1285,7 +1293,7 @@ toNumberReport source number row col =
12851293
12861294 NumberNoLeadingZero ->
12871295 Report.Report "LEADING ZEROS" region [] $
1288− Report.toCodeSnippet source region Nothing
1296+ Code.toSnippet source region Nothing
12891297 (
12901298 D.reflow $
12911299 "I do not accept numbers with leading zeros:"
@@ -1303,15 +1311,19 @@ toNumberReport source number row col =
13031311 )
13041312
13051313
1306−toOperatorReport :: Code.Source -> Context -> Operator -> Row -> Col -> Report.Report
1314+
1315+-- OPERATORS
1316+
1317+
1318+toOperatorReport :: Code.Source -> Context -> BadOperator -> Row -> Col -> Report.Report
13071319toOperatorReport source context operator row col =
13081320 case operator of
1309− OpDot ->
1321+ BadDot ->
13101322 let
13111323 region = toRegion row col
13121324 in
13131325 Report.Report "UNEXPECTED SYMBOL" region [] $
1314− Report.toCodeSnippet source region Nothing
1326+ Code.toSnippet source region Nothing
13151327 (
13161328 "I was not expecting this dot:"
13171329 ,
@@ -1321,12 +1333,12 @@ toOperatorReport source context operator row col =
13211333 \ there is some extra whitespace?"
13221334 )
13231335
1324− OpPipe ->
1336+ BadPipe ->
13251337 let
13261338 region = toRegion row col
13271339 in
13281340 Report.Report "UNEXPECTED SYMBOL" region [] $
1329− Report.toCodeSnippet source region Nothing
1341+ Code.toSnippet source region Nothing
13301342 (
13311343 D.reflow $
13321344 "I was not expecting this vertical bar:"
@@ -1335,12 +1347,12 @@ toOperatorReport source context operator row col =
13351347 "Vertical bars should only appear in custom type declarations. Maybe you want || instead?"
13361348 )
13371349
1338− OpArrow ->
1350+ BadArrow ->
13391351 let
13401352 region = toWiderRegion row col 2
13411353 in
13421354 Report.Report "UNEXPECTED ARROW" region [] $
1343− Report.toCodeSnippet source region Nothing $
1355+ Code.toSnippet source region Nothing $
13441356 if error "TODO inCase" then
13451357 (
13461358 D.reflow $
@@ -1370,13 +1382,13 @@ toOperatorReport source context operator row col =
13701382 \ you want > or >= instead?"
13711383 )
13721384
1373− OpEquals ->
1385+ BadEquals ->
13741386 let
13751387 region = toRegion row col
13761388 name = getDefName context
13771389 in
13781390 Report.Report "UNEXPECTED EQUALS" region [] $
1379− Report.toCodeSnippet source region Nothing
1391+ Code.toSnippet source region Nothing
13801392 (
13811393 D.reflow $
13821394 "I was not expecting to see this equals sign:"
@@ -1398,13 +1410,13 @@ toOperatorReport source context operator row col =
13981410 ]
13991411 )
14001412
1401− OpHasType ->
1413+ BadHasType ->
14021414 let
14031415 region = toRegion row col
14041416 name = getDefName context
14051417 in
14061418 Report.Report "UNEXPECTED SYMBOL" region [] $
1407− Report.toCodeSnippet source region Nothing $
1419+ Code.toSnippet source region Nothing $
14081420 (
14091421 D.reflow $
14101422 "I was not expecting to run into the \"has type\" symbol here:"
@@ -1445,7 +1457,7 @@ toIfReport source context if_ startRow startCol =
14451457 region = toRegion row col
14461458 in
14471459 Report.Report "UNFINISHED IF" region [] $
1448− Report.toCodeSnippet source surroundings (Just region)
1460+ Code.toSnippet source surroundings (Just region)
14491461 (
14501462 D.reflow $
14511463 "I was expecting to see more of this `if` expression, but I got stuck here:"
@@ -1461,7 +1473,7 @@ toIfReport source context if_ startRow startCol =
14611473 region = toRegion row col
14621474 in
14631475 Report.Report "UNFINISHED IF" region [] $
1464− Report.toCodeSnippet source surroundings (Just region)
1476+ Code.toSnippet source surroundings (Just region)
14651477 (
14661478 D.reflow $
14671479 "I was expecting to see more of this `if` expression, but I got stuck here:"
@@ -1477,7 +1489,7 @@ toIfReport source context if_ startRow startCol =
14771489 region = toRegion row col
14781490 in
14791491 Report.Report "UNFINISHED IF" region [] $
1480− Report.toCodeSnippet source surroundings (Just region)
1492+ Code.toSnippet source surroundings (Just region)
14811493 (
14821494 D.reflow $
14831495 "I just saw the start of an `else` branch, but then I got stuck here:"
@@ -1501,7 +1513,7 @@ toIfReport source context if_ startRow startCol =
15011513 region = toRegion row col
15021514 in
15031515 Report.Report "UNFINISHED IF" region [] $
1504− Report.toCodeSnippet source surroundings (Just region)
1516+ Code.toSnippet source surroundings (Just region)
15051517 (
15061518 D.reflow $
15071519 "I was expecting to see more of this `if` expression, but I got stuck here:"
@@ -1522,7 +1534,7 @@ toIfReport source context if_ startRow startCol =
15221534 region = toRegion row col
15231535 in
15241536 Report.Report "UNFINISHED IF" region [] $
1525− Report.toCodeSnippet source surroundings (Just region)
1537+ Code.toSnippet source surroundings (Just region)
15261538 (
15271539 D.reflow $
15281540 "I was expecting to see more of this `if` expression, but I got stuck here:"
@@ -1542,7 +1554,7 @@ toIfReport source context if_ startRow startCol =
15421554 region = toRegion row col
15431555 in
15441556 Report.Report "UNFINISHED IF" region [] $
1545− Report.toCodeSnippet source surroundings (Just region)
1557+ Code.toSnippet source surroundings (Just region)
15461558 (
15471559 D.reflow $
15481560 "I got stuck after the start of this `then` branch:"
@@ -1562,7 +1574,7 @@ toIfReport source context if_ startRow startCol =
15621574 region = toRegion row col
15631575 in
15641576 Report.Report "UNFINISHED IF" region [] $
1565− Report.toCodeSnippet source surroundings (Just region)
1577+ Code.toSnippet source surroundings (Just region)
15661578 (
15671579 D.reflow $
15681580 "I got stuck after the start of this `else` branch:"
@@ -1582,7 +1594,7 @@ toIfReport source context if_ startRow startCol =
15821594 region = toRegion row col
15831595 in
15841596 Report.Report "UNFINISHED IF" region [] $
1585− Report.toCodeSnippet source surroundings (Just region)
1597+ Code.toSnippet source surroundings (Just region)
15861598 (
15871599 D.reflow $
15881600 "I was expecting to see an `else` branch after this:"
@@ -1608,38 +1620,51 @@ toRecordReport source context record startRow startCol =
16081620 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
16091621 region = toRegion row col
16101622 in
1611− Report.Report "UNFINISHED PARENTHESES" region [] $
1612− Report.toCodeSnippet source surroundings (Just region)
1613− (
1614− D.reflow $
1615− "I was expecting to see a closing curly brace next, but I got stuck here:"
1616− ,
1617− D.stack
1618− [ D.fillSep ["Try","adding","a",D.dullyellow "}","to","see","if","that","helps?"]
1619− , D.toSimpleNote $
1620− "I can get stuck when I run into keywords, operators, parentheses, or brackets\
1621− \ unexpectedly. So there may be some other syntax trouble (like an extra\
1622− \ parenthesis?) that is confusing me."
1623− ]
1624− )
1623+ case Code.whatIsNext source row col of
1624+ Keyword keyword ->
1625+ Report.Report "RESERVED WORD" region [] $
1626+ Code.toSnippet source surroundings (Just region)
1627+ (
1628+ D.reflow $
1629+ "I just started parsing a record, but I got stuck on this field name:"
1630+ ,
1631+ D.reflow $
1632+ "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
1633+ \ that is a reserved word. Try using a different name!"
1634+ )
1635+
1636+ _ ->
1637+ Report.Report "UNFINISHED RECORD" region [] $
1638+ Code.toSnippet source surroundings (Just region)
1639+ (
1640+ D.reflow $
1641+ "I just started parsing a record, but I got stuck here:"
1642+ ,
1643+ D.fillSep
1644+ ["Records","look","like",D.dullyellow "{ x = 3, y = 4 },"
1645+ ,"so","I","was","expecting","to","see","a","field","name","next."
1646+ ]
1647+ )
16251648
16261649 RecordEnd row col ->
16271650 let
16281651 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
16291652 region = toRegion row col
16301653 in
1631− Report.Report "UNFINISHED PARENTHESES" region [] $
1632− Report.toCodeSnippet source surroundings (Just region)
1654+ Report.Report "UNFINISHED RECORD" region [] $
1655+ Code.toSnippet source surroundings (Just region)
16331656 (
16341657 D.reflow $
1635− "I was expecting to see a closing curly brace next, but I got stuck here:"
1658+ "I am partway through parsing a record, but I got stuck here:"
16361659 ,
16371660 D.stack
1638− [ D.fillSep ["Try","adding","a",D.dullyellow "}","to","see","if","that","helps?"]
1661+ [ D.fillSep
1662+ ["I","was","expecting","to","see","a","closing","curly","brace","before","this,"
1663+ ,"so","try","adding","a",D.dullyellow "}","and","see","if","that","helps?"
1664+ ]
16391665 , D.toSimpleNote $
1640− "I can get stuck when I run into keywords, operators, parentheses, or brackets\
1641− \ unexpectedly. So there may be some other syntax trouble (like an extra\
1642− \ parenthesis?) that is confusing me."
1666+ "When I get stuck like this, it usually means that there is a missing parenthesis\
1667+ \ or bracket somewhere earlier. It could also be a stray keyword or operator."
16431668 ]
16441669 )
16451670
@@ -1648,18 +1673,32 @@ toRecordReport source context record startRow startCol =
16481673 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
16491674 region = toRegion row col
16501675 in
1651− Report.Report "UNFINISHED RECORD" region [] $
1652− Report.toCodeSnippet source surroundings (Just region)
1653− (
1654− D.reflow $
1655− "I am partway through parsing a record, but I got stuck after that last comma:"
1656− ,
1657− addNoteForRecordError $
1658− D.reflow $
1659− "Trailing commas are not allowed in records, so I was expecting to see another\
1660− \ record field defined next. If you are done defining the record, the fix may\
1661− \ be to delete that last comma?"
1662− )
1676+ case Code.whatIsNext source row col of
1677+ Code.Keyword keyword ->
1678+ Report.Report "RESERVED WORD" region [] $
1679+ Code.toSnippet source surroundings (Just region)
1680+ (
1681+ D.reflow $
1682+ "I am partway through parsing a record, but I got stuck on this field name:"
1683+ ,
1684+ D.reflow $
1685+ "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
1686+ \ that is a reserved word. Try using a different name!"
1687+ )
1688+
1689+ _ ->
1690+ Report.Report "UNFINISHED RECORD" region [] $
1691+ Code.toSnippet source surroundings (Just region)
1692+ (
1693+ D.reflow $
1694+ "I am partway through parsing a record, but I got stuck after that last comma:"
1695+ ,
1696+ addNoteForRecordError $
1697+ D.reflow $
1698+ "Trailing commas are not allowed in records, so I was expecting to see another\
1699+ \ record field defined next. If you are done defining the record, the fix may\
1700+ \ be to delete that last comma?"
1701+ )
16631702
16641703 RecordEquals row col ->
16651704 let
@@ -1667,7 +1706,7 @@ toRecordReport source context record startRow startCol =
16671706 region = toRegion row col
16681707 in
16691708 Report.Report "UNFINISHED RECORD" region [] $
1670− Report.toCodeSnippet source surroundings (Just region)
1709+ Code.toSnippet source surroundings (Just region)
16711710 (
16721711 D.reflow $
16731712 "I am partway through parsing a record, but I got stuck here:"
@@ -1691,7 +1730,7 @@ toRecordReport source context record startRow startCol =
16911730 region = toRegion row col
16921731 in
16931732 Report.Report "UNFINISHED RECORD" region [] $
1694− Report.toCodeSnippet source surroundings (Just region)
1733+ Code.toSnippet source surroundings (Just region)
16951734 (
16961735 D.reflow $
16971736 "I just saw the opening curly brace of a record, but then I got stuck here:"
@@ -1709,7 +1748,7 @@ toRecordReport source context record startRow startCol =
17091748 region = toRegion row col
17101749 in
17111750 Report.Report "UNFINISHED RECORD" region [] $
1712− Report.toCodeSnippet source surroundings (Just region)
1751+ Code.toSnippet source surroundings (Just region)
17131752 (
17141753 D.reflow $
17151754 "I was expecting to see a closing curly brace next:"
@@ -1726,7 +1765,7 @@ toRecordReport source context record startRow startCol =
17261765 region = toRegion row col
17271766 in
17281767 Report.Report "UNFINISHED RECORD" region [] $
1729− Report.toCodeSnippet source surroundings (Just region)
1768+ Code.toSnippet source surroundings (Just region)
17301769 (
17311770 D.reflow $
17321771 "I am partway through parsing a record, but I got stuck after that last comma:"
@@ -1744,7 +1783,7 @@ toRecordReport source context record startRow startCol =
17441783 region = toRegion row col
17451784 in
17461785 Report.Report "UNFINISHED RECORD" region [] $
1747− Report.toCodeSnippet source surroundings (Just region)
1786+ Code.toSnippet source surroundings (Just region)
17481787 (
17491788 D.reflow $
17501789 "I am partway through parsing a record. I just saw a record\
@@ -1762,7 +1801,7 @@ toRecordReport source context record startRow startCol =
17621801 region = toRegion row col
17631802 in
17641803 Report.Report "UNFINISHED RECORD" region [] $
1765− Report.toCodeSnippet source surroundings (Just region)
1804+ Code.toSnippet source surroundings (Just region)
17661805 (
17671806 D.reflow $
17681807 "I am partway through parsing a record, and I was expecting to run into an expression next:"
@@ -1835,7 +1874,7 @@ toTupleReport source context tuple startRow startCol =
18351874 region = toRegion row col
18361875 in
18371876 Report.Report "UNFINISHED PARENTHESES" region [] $
1838− Report.toCodeSnippet source surroundings (Just region)
1877+ Code.toSnippet source surroundings (Just region)
18391878 (
18401879 D.reflow $
18411880 "I was expecting to see a closing parentheses next, but I got stuck here:"
@@ -1844,8 +1883,8 @@ toTupleReport source context tuple startRow startCol =
18441883 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
18451884 , D.toSimpleNote $
18461885 "I can get stuck when I run into keywords, operators, parentheses, or brackets\
1847− \ unexpectedly. So there may be some other syntax trouble (like an extra\
1848− \ square bracket?) that is confusing me."
1886+ \ unexpectedly. So there may be some earlier syntax trouble (like extra parenthesis\
1887+ \ or missing brackets) that is confusing me."
18491888 ]
18501889 )
18511890
@@ -1855,7 +1894,7 @@ toTupleReport source context tuple startRow startCol =
18551894 region = toRegion row col
18561895 in
18571896 Report.Report "UNFINISHED OPERATOR FUNCTION" region [] $
1858− Report.toCodeSnippet source surroundings (Just region)
1897+ Code.toSnippet source surroundings (Just region)
18591898 (
18601899 D.reflow "I was expecting a closing parenthesis here:"
18611900 ,
@@ -1874,18 +1913,18 @@ toTupleReport source context tuple startRow startCol =
18741913 region = toRegion row col
18751914 in
18761915 Report.Report "UNEXPECTED SYMBOL" region [] $
1877− Report.toCodeSnippet source surroundings (Just region)
1916+ Code.toSnippet source surroundings (Just region)
18781917 (
18791918 D.reflow $
18801919 "I ran into an unexpected symbol here:"
18811920 ,
18821921 D.fillSep $
18831922 case operator of
1884− OpDot -> ["Maybe","you","wanted","a","record","accessor","like",D.dullyellow ".x","or",D.dullyellow ".name","instead?"]
1885− OpPipe -> ["Try",D.dullyellow "(||)","instead?","To","turn","boolean","OR","into","a","function?"]
1886− OpArrow -> ["Maybe","you","wanted",D.dullyellow "(>)","or",D.dullyellow "(>=)","instead?"]
1887− OpEquals -> ["Try",D.dullyellow "(==)","instead?","To","make","a","function","that","checks","equality?"]
1888− OpHasType -> ["Try",D.dullyellow "(::)","instead?","To","add","values","to","the","front","of","lists?"]
1923+ BadDot -> ["Maybe","you","wanted","a","record","accessor","like",D.dullyellow ".x","or",D.dullyellow ".name","instead?"]
1924+ BadPipe -> ["Try",D.dullyellow "(||)","instead?","To","turn","boolean","OR","into","a","function?"]
1925+ BadArrow -> ["Maybe","you","wanted",D.dullyellow "(>)","or",D.dullyellow "(>=)","instead?"]
1926+ BadEquals -> ["Try",D.dullyellow "(==)","instead?","To","make","a","function","that","checks","equality?"]
1927+ BadHasType -> ["Try",D.dullyellow "(::)","instead?","To","add","values","to","the","front","of","lists?"]
18891928 )
18901929
18911930 TupleIndentExpr1 row col ->
@@ -1894,7 +1933,7 @@ toTupleReport source context tuple startRow startCol =
18941933 region = toRegion row col
18951934 in
18961935 Report.Report "UNFINISHED PARENTHESES" region [] $
1897− Report.toCodeSnippet source surroundings (Just region)
1936+ Code.toSnippet source surroundings (Just region)
18981937 (
18991938 D.reflow $
19001939 "I just saw an open parenthesis, so I was expecting to see an expression next."
@@ -1917,7 +1956,7 @@ toTupleReport source context tuple startRow startCol =
19171956 region = toRegion row col
19181957 in
19191958 Report.Report "UNFINISHED TUPLE" region [] $
1920− Report.toCodeSnippet source surroundings (Just region)
1959+ Code.toSnippet source surroundings (Just region)
19211960 (
19221961 D.reflow $
19231962 "I think I am in the middle of parsing a tuple. I just saw a comma, so I was expecting to see expression next."
@@ -1940,7 +1979,7 @@ toTupleReport source context tuple startRow startCol =
19401979 region = toRegion row col
19411980 in
19421981 Report.Report "UNFINISHED PARENTHESES" region [] $
1943− Report.toCodeSnippet source surroundings (Just region)
1982+ Code.toSnippet source surroundings (Just region)
19441983 (
19451984 D.reflow $
19461985 "I was expecting to see a closing parenthesis next:"
@@ -1966,17 +2005,19 @@ toListReport source context list startRow startCol =
19662005 region = toRegion row col
19672006 in
19682007 Report.Report "UNFINISHED LIST" region [] $
1969− Report.toCodeSnippet source surroundings (Just region)
2008+ Code.toSnippet source surroundings (Just region)
19702009 (
19712010 D.reflow $
1972− "I was expecting to see a closing square bracket next, but I got stuck here:"
2011+ "I am partway through parsing a list, but I got stuck here:"
19732012 ,
19742013 D.stack
1975− [ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
2014+ [ D.fillSep
2015+ ["I","was","expecting","to","see","a","closing","square","bracket","before","this,"
2016+ ,"so","try","adding","a",D.dullyellow "]","and","see","if","that","helps?"
2017+ ]
19762018 , D.toSimpleNote $
1977− "I can get stuck when I run into keywords, operators, parentheses, or brackets\
1978− \ unexpectedly. So there may be some other syntax trouble (like an extra\
1979− \ parenthesis?) that is confusing me."
2019+ "When I get stuck like this, it usually means that there is a missing parenthesis\
2020+ \ or bracket somewhere earlier. It could also be a stray keyword or operator."
19802021 ]
19812022 )
19822023
@@ -1988,7 +2029,7 @@ toListReport source context list startRow startCol =
19882029 region = toRegion r c
19892030 in
19902031 Report.Report "UNFINISHED LIST" region [] $
1991− Report.toCodeSnippet source surroundings (Just region)
2032+ Code.toSnippet source surroundings (Just region)
19922033 (
19932034 D.reflow $
19942035 "I was expecting to see another list entry after that last comma:"
@@ -2020,17 +2061,19 @@ toListReport source context list startRow startCol =
20202061 region = toRegion row col
20212062 in
20222063 Report.Report "UNFINISHED LIST" region [] $
2023− Report.toCodeSnippet source surroundings (Just region)
2064+ Code.toSnippet source surroundings (Just region)
20242065 (
20252066 D.reflow $
2026− "I was expecting to see a closing square bracket next, but I got stuck here:"
2067+ "I am partway through parsing a list, but I got stuck here:"
20272068 ,
20282069 D.stack
2029− [ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
2070+ [ D.fillSep
2071+ ["I","was","expecting","to","see","a","closing","square","bracket","before","this,"
2072+ ,"so","try","adding","a",D.dullyellow "]","and","see","if","that","helps?"
2073+ ]
20302074 , D.toSimpleNote $
2031− "I can get stuck when I run into keywords, operators, parentheses, or brackets\
2032− \ unexpectedly. So there may be some other syntax trouble (like an extra\
2033− \ parenthesis?) that is confusing me."
2075+ "When I get stuck like this, it usually means that there is a missing parenthesis\
2076+ \ or bracket somewhere earlier. It could also be a stray keyword or operator."
20342077 ]
20352078 )
20362079
@@ -2040,7 +2083,7 @@ toListReport source context list startRow startCol =
20402083 region = toRegion row col
20412084 in
20422085 Report.Report "UNFINISHED LIST" region [] $
2043− Report.toCodeSnippet source surroundings (Just region)
2086+ Code.toSnippet source surroundings (Just region)
20442087 (
20452088 D.reflow $
20462089 "I cannot find the end of this list:"
@@ -2076,7 +2119,7 @@ toListReport source context list startRow startCol =
20762119 region = toRegion row col
20772120 in
20782121 Report.Report "UNFINISHED LIST" region [] $
2079− Report.toCodeSnippet source surroundings (Just region)
2122+ Code.toSnippet source surroundings (Just region)
20802123 (
20812124 D.reflow $
20822125 "I cannot find the end of this list:"
@@ -2108,7 +2151,7 @@ toListReport source context list startRow startCol =
21082151 region = toRegion row col
21092152 in
21102153 Report.Report "UNFINISHED LIST" region [] $
2111− Report.toCodeSnippet source surroundings (Just region)
2154+ Code.toSnippet source surroundings (Just region)
21122155 (
21132156 D.reflow $
21142157 "I was expecting to see another list entry after this comma:"
@@ -2149,18 +2192,32 @@ toFuncReport source context func startRow startCol =
21492192 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
21502193 region = toRegion row col
21512194 in
2152− Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
2153− Report.toCodeSnippet source surroundings (Just region)
2154− (
2155− D.reflow $
2156− "I just saw the beginning of an anonymous function, so I was expecting to see an arrow next:"
2157− ,
2158− D.fillSep $
2159− ["The","syntax","for","anonymous","functions","is"
2160− ,D.dullyellow "(\\x -> x + 1)"
2161− ,"so","I","am","missing","the","arrow","and","the","body","of","the","function."
2162− ]
2163− )
2195+ case Code.whatIsNext source row col of
2196+ Code.Keyword keyword ->
2197+ Report.Report "RESERVED WORD" region [] $
2198+ Code.toSnippet source surroundings (Just region)
2199+ (
2200+ D.reflow $
2201+ "I was parsing an anonymous function, but I got stuck here:"
2202+ ,
2203+ D.reflow $
2204+ "It looks like you are trying to use `" ++ keyword ++ "` as an argument, but\
2205+ \ it is a reserved word in this language. Try using a different argument name!"
2206+ )
2207+
2208+ _ ->
2209+ Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
2210+ Code.toSnippet source surroundings (Just region)
2211+ (
2212+ D.reflow $
2213+ "I just saw the beginning of an anonymous function, so I was expecting to see an arrow next:"
2214+ ,
2215+ D.fillSep $
2216+ ["The","syntax","for","anonymous","functions","is"
2217+ ,D.dullyellow "(\\x -> x + 1)"
2218+ ,"so","I","am","missing","the","arrow","and","the","body","of","the","function."
2219+ ]
2220+ )
21642221
21652222 FuncIndentArg row col ->
21662223 let
@@ -2168,7 +2225,7 @@ toFuncReport source context func startRow startCol =
21682225 region = toRegion row col
21692226 in
21702227 Report.Report "MISSING ARGUMENT" region [] $
2171− Report.toCodeSnippet source surroundings (Just region)
2228+ Code.toSnippet source surroundings (Just region)
21722229 (
21732230 D.reflow $
21742231 "I just saw the beginning of an anonymous function, so I was expecting to see an argument next:"
@@ -2191,7 +2248,7 @@ toFuncReport source context func startRow startCol =
21912248 region = toRegion row col
21922249 in
21932250 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
2194− Report.toCodeSnippet source surroundings (Just region)
2251+ Code.toSnippet source surroundings (Just region)
21952252 (
21962253 D.reflow $
21972254 "I just saw the beginning of an anonymous function, so I was expecting to see an arrow next:"
@@ -2216,7 +2273,7 @@ toFuncReport source context func startRow startCol =
22162273 region = toRegion row col
22172274 in
22182275 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
2219− Report.toCodeSnippet source surroundings (Just region)
2276+ Code.toSnippet source surroundings (Just region)
22202277 (
22212278 D.reflow $
22222279 "I was expecting to see the body of your anonymous function next:"
@@ -2242,7 +2299,7 @@ toFuncReport source context func startRow startCol =
22422299 case err of
22432300 CommentOnNothing region ->
22442301 Report.Report "STRAY COMMENT" region [] $
2245− Report.toCodeSnippet source region Nothing
2302+ Code.toSnippet source region Nothing
22462303 (
22472304 "This documentation comment is not followed by anything."
22482305 ,
@@ -2254,7 +2311,7 @@ toFuncReport source context func startRow startCol =
22542311
22552312 UnexpectedPort region ->
22562313 Report.Report "UNEXPECTED PORTS" region [] $
2257− Report.toCodeSnippet source region Nothing
2314+ Code.toSnippet source region Nothing
22582315 (
22592316 D.reflow $
22602317 "You are declaring ports in a normal module."
@@ -2273,7 +2330,7 @@ toFuncReport source context func startRow startCol =
22732330
22742331 NoPorts region ->
22752332 Report.Report "NO PORTS" region [] $
2276− Report.toCodeSnippet source region Nothing
2333+ Code.toSnippet source region Nothing
22772334 (
22782335 D.reflow $
22792336 "This module does not declare any ports, but it says it will:"
@@ -2293,7 +2350,7 @@ toFuncReport source context func startRow startCol =
22932350
22942351 DocComment ->
22952352 Report.Report "EXPECTING DOC COMMENT" region [] $
2296− Report.toCodeSnippet source region Nothing
2353+ Code.toSnippet source region Nothing
22972354 (
22982355 D.reflow $
22992356 "I was expecting a doc comment here:"
@@ -2306,7 +2363,7 @@ toFuncReport source context func startRow startCol =
23062363
23072364 Precedence ->
23082365 Report.Report "EXPECTING PRECEDENCE" region [] $
2309− Report.toCodeSnippet source region Nothing
2366+ Code.toSnippet source region Nothing
23102367 (
23112368 D.reflow $
23122369 "I was expecting the precedence here:"
@@ -2317,7 +2374,7 @@ toFuncReport source context func startRow startCol =
23172374
23182375 Wildcard ->
23192376 Report.Report "EXPECTING A WILDCARD" region [] $
2320− Report.toCodeSnippet source region Nothing
2377+ Code.toSnippet source region Nothing
23212378 (
23222379 D.reflow $
23232380 "I was expecting a _ here:"
@@ -2333,7 +2390,7 @@ toFuncReport source context func startRow startCol =
23332390 A.Region (A.Position row startCol) (A.Position row endCol)
23342391 in
23352392 Report.Report "INVALID PATTERN" badRegion [] $
2336− Report.toCodeSnippet source badRegion Nothing
2393+ Code.toSnippet source badRegion Nothing
23372394 (
23382395 D.reflow $
23392396 "I was expecting to see an underscore without any additional characters:"
@@ -2347,7 +2404,7 @@ toFuncReport source context func startRow startCol =
23472404
23482405 FloatInPattern ->
23492406 Report.Report "INVALID PATTERN" region [] $
2350− Report.toCodeSnippet source region Nothing
2407+ Code.toSnippet source region Nothing
23512408 (
23522409 D.reflow $
23532410 "I cannot pattern match with floating point numbers:"
@@ -2361,7 +2418,7 @@ toFuncReport source context func startRow startCol =
23612418
23622419 MatchingName name ->
23632420 Report.Report "EXPECTING A DEFINITION" region [] $
2364− Report.toCodeSnippet source region Nothing
2421+ Code.toSnippet source region Nothing
23652422 (
23662423 D.reflow $
23672424 "I just saw the type annotation for `" ++ Name.toChars name
@@ -2377,7 +2434,7 @@ toFuncReport source context func startRow startCol =
23772434
23782435 TypeWithBadDefinition region annName defName ->
23792436 Report.Report "ANNOTATION MISMATCH" region [] $
2380− Report.toCodeSnippet source region Nothing
2437+ Code.toSnippet source region Nothing
23812438 (
23822439 D.reflow $
23832440 "I see a `" <> Name.toChars annName