on master help sign in
Add remaining syntax messages for type declarations / make EOF message much better
commit4d4225d138ea437822004858b5819011af3e33a2 authorEvan Czaplicki <evancz@users.noreply.github.com> dateFri 17 May 2019, 15:07 (7 years ago) parent894fc40
1 file changed+248−23
compiler/src/Reporting/Error/Syntax.hs+248−23
compiler/src/Reporting/Error/Syntax.hs+248−23
@@ -583,19 +583,64 @@ toParseErrorReport source modul =
583583 toSpaceReport source space row col
584584
585585 ModuleEndOfFile row col ->
586− let
587− region = toRegion row col
588− in
589− Report.Report "EXPECTING END OF FILE" region [] $
590− Code.toSnippet source region Nothing
591− (
592− D.reflow $
593− "I was not expecting to see anything more here:"
594− ,
595− D.reflow $
596− "I think I have read all the declarations in the file and that there is nothing\
597− \ left to see, so whatever I am running into is confusing me a lot!"
598− )
586+ case Code.whatIsNext source row col of
587+ Code.Keyword keyword ->
588+ let
589+ region = toKeywordRegion row col keyword
590+ in
591+ Report.Report "RESERVED WORD" region [] $
592+ Code.toSnippet source region Nothing
593+ (
594+ D.reflow $
595+ "I got stuck on this reserved word:"
596+ ,
597+ D.reflow $
598+ "The name `" ++ keyword ++ "` is reserved, so try using a different name?"
599+ )
600+
601+ Code.Operator op ->
602+ let
603+ region = toKeywordRegion row col op
604+ in
605+ Report.Report "UNEXPECTED SYMBOL" region [] $
606+ Code.toSnippet source region Nothing
607+ (
608+ D.reflow $
609+ "I ran into an unexpected symbol:"
610+ ,
611+ D.reflow $
612+ "I was not expecting to see a " ++ op ++ " here. Try deleting it? Maybe\
613+ \ I can give a better hint from there?"
614+ )
615+
616+ Code.Close term bracket ->
617+ let
618+ region = toRegion row col
619+ in
620+ Report.Report ("UNEXPECTED " ++ map Char.toUpper term) region [] $
621+ Code.toSnippet source region Nothing
622+ (
623+ D.reflow $
624+ "I ran into an unexpected " ++ term ++ ":"
625+ ,
626+ D.reflow $
627+ "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
628+ )
629+
630+ Code.Other ->
631+ let
632+ region = toRegion row col
633+ in
634+ Report.Report "SYNTAX PROBLEM" region [] $
635+ Code.toSnippet source region Nothing
636+ (
637+ D.reflow $
638+ "I got stuck here:"
639+ ,
640+ D.reflow $
641+ "Whatever I am running into is confusing me a lot! Normally I can give fairly\
642+ \ specific hints, but something is really tripping me up this time."
643+ )
599644
600645 ModuleProblem row col ->
601646 let
@@ -1060,7 +1105,7 @@ toTypeAliasReport source typeAlias startRow startCol =
10601105 Code.toSnippet source surroundings (Just region)
10611106 (
10621107 D.reflow $
1063− "I think I am parsing a type alias, but I got stuck here:"
1108+ "I am partway through parsing a type alias, but I got stuck here:"
10641109 ,
10651110 D.stack
10661111 [ D.fillSep $
@@ -1072,13 +1117,64 @@ toTypeAliasReport source typeAlias startRow startCol =
10721117 )
10731118
10741119 AliasEquals row col ->
1075− error "TODO AliasEquals" row col
1120+ case Code.whatIsNext source row col of
1121+ Code.Keyword keyword ->
1122+ let
1123+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1124+ region = toKeywordRegion row col keyword
1125+ in
1126+ Report.Report "RESERVED WORD" region [] $
1127+ Code.toSnippet source surroundings (Just region)
1128+ (
1129+ D.reflow $
1130+ "I ran into a reserved word unexpectedly while parsing this type alias:"
1131+ ,
1132+ D.stack
1133+ [ D.reflow $
1134+ "It looks like you are trying use `" ++ keyword
1135+ ++ "` as a type variable, but it is a reserved word. Try using a different name?"
1136+ , typeAliasNote
1137+ ]
1138+ )
1139+
1140+ _ ->
1141+ let
1142+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1143+ region = toRegion row col
1144+ in
1145+ Report.Report "PROBLEM IN TYPE ALIAS" region [] $
1146+ Code.toSnippet source surroundings (Just region)
1147+ (
1148+ D.reflow $
1149+ "I am partway through parsing a type alias, but I got stuck here:"
1150+ ,
1151+ D.stack
1152+ [ D.reflow $
1153+ "I was expecting to see a type variable or an an equals sign next."
1154+ , typeAliasNote
1155+ ]
1156+ )
10761157
10771158 AliasBody tipe row col ->
10781159 toTypeReport source tipe row col
10791160
10801161 AliasIndentEquals row col ->
1081− error "TODO AliasIndentEquals" row col
1162+ let
1163+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1164+ region = toRegion row col
1165+ in
1166+ Report.Report "UNFINISHED TYPE ALIAS" region [] $
1167+ Code.toSnippet source surroundings (Just region)
1168+ (
1169+ D.reflow $
1170+ "I am partway through parsing a type alias, but I got stuck here:"
1171+ ,
1172+ D.stack
1173+ [ D.reflow $
1174+ "I was expecting to see a type variable or an an equals sign next."
1175+ , typeAliasNote
1176+ ]
1177+ )
10821178
10831179 AliasIndentBody row col ->
10841180 let
@@ -1149,28 +1245,157 @@ toCustomTypeReport source customType startRow startCol =
11491245 )
11501246
11511247 CT_Equals row col ->
1152− error "TODO CT_Equals" row col
1248+ case Code.whatIsNext source row col of
1249+ Code.Keyword keyword ->
1250+ let
1251+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1252+ region = toKeywordRegion row col keyword
1253+ in
1254+ Report.Report "RESERVED WORD" region [] $
1255+ Code.toSnippet source surroundings (Just region)
1256+ (
1257+ D.reflow $
1258+ "I ran into a reserved word unexpectedly while parsing this custom type:"
1259+ ,
1260+ D.stack
1261+ [ D.reflow $
1262+ "It looks like you are trying use `" ++ keyword
1263+ ++ "` as a type variable, but it is a reserved word. Try using a different name?"
1264+ , customTypeNote
1265+ ]
1266+ )
1267+
1268+ _ ->
1269+ let
1270+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1271+ region = toRegion row col
1272+ in
1273+ Report.Report "PROBLEM IN CUSTOM TYPE" region [] $
1274+ Code.toSnippet source surroundings (Just region)
1275+ (
1276+ D.reflow $
1277+ "I am partway through parsing a custom type, but I got stuck here:"
1278+ ,
1279+ D.stack
1280+ [ D.reflow $
1281+ "I was expecting to see a type variable or an an equals sign next."
1282+ , customTypeNote
1283+ ]
1284+ )
11531285
11541286 CT_Bar row col ->
1155− error "TODO CT_Bar" row col
1287+ let
1288+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1289+ region = toRegion row col
1290+ in
1291+ Report.Report "PROBLEM IN CUSTOM TYPE" region [] $
1292+ Code.toSnippet source surroundings (Just region)
1293+ (
1294+ D.reflow $
1295+ "I am partway through parsing a custom type, but I got stuck here:"
1296+ ,
1297+ D.stack
1298+ [ D.reflow $
1299+ "I was expecting to see a vertical bar like | next."
1300+ , customTypeNote
1301+ ]
1302+ )
11561303
11571304 CT_Variant row col ->
1158− error "TODO CT_Variant" row col
1305+ let
1306+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1307+ region = toRegion row col
1308+ in
1309+ Report.Report "PROBLEM IN CUSTOM TYPE" region [] $
1310+ Code.toSnippet source surroundings (Just region)
1311+ (
1312+ D.reflow $
1313+ "I am partway through parsing a custom type, but I got stuck here:"
1314+ ,
1315+ D.stack
1316+ [ D.fillSep $
1317+ ["I","was","expecting","to","see","a","variant","name","next."
1318+ ,"Something","like",D.dullyellow "Success","or",D.dullyellow "Sandwich" <> "."
1319+ ,"Any","name","that","starts","with","a","capital","letter","really!"
1320+ ]
1321+ , customTypeNote
1322+ ]
1323+ )
11591324
11601325 CT_VariantArg tipe row col ->
11611326 toTypeReport source tipe row col
11621327
11631328 CT_IndentEquals row col ->
1164− error "TODO CT_IndentEquals" row col
1329+ let
1330+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1331+ region = toRegion row col
1332+ in
1333+ Report.Report "UNFINISHED CUSTOM TYPE" region [] $
1334+ Code.toSnippet source surroundings (Just region)
1335+ (
1336+ D.reflow $
1337+ "I am partway through parsing a custom type, but I got stuck here:"
1338+ ,
1339+ D.stack
1340+ [ D.reflow $
1341+ "I was expecting to see a type variable or an an equals sign next."
1342+ , customTypeNote
1343+ ]
1344+ )
11651345
11661346 CT_IndentBar row col ->
1167− error "TODO CT_IndentBar" row col
1347+ let
1348+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1349+ region = toRegion row col
1350+ in
1351+ Report.Report "UNFINISHED CUSTOM TYPE" region [] $
1352+ Code.toSnippet source surroundings (Just region)
1353+ (
1354+ D.reflow $
1355+ "I am partway through parsing a custom type, but I got stuck here:"
1356+ ,
1357+ D.stack
1358+ [ D.reflow $
1359+ "I was expecting to see a vertical bar like | next."
1360+ , customTypeNote
1361+ ]
1362+ )
11681363
11691364 CT_IndentAfterBar row col ->
1170− error "TODO CT_IndentAfterBar" row col
1365+ let
1366+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1367+ region = toRegion row col
1368+ in
1369+ Report.Report "UNFINISHED CUSTOM TYPE" region [] $
1370+ Code.toSnippet source surroundings (Just region)
1371+ (
1372+ D.reflow $
1373+ "I am partway through parsing a custom type, but I got stuck here:"
1374+ ,
1375+ D.stack
1376+ [ D.reflow $
1377+ "I just saw a vertical bar, so I was expecting to see another variant defined next."
1378+ , customTypeNote
1379+ ]
1380+ )
11711381
11721382 CT_IndentAfterEquals row col ->
1173− error "TODO CT_IndentAfterEquals" row col
1383+ let
1384+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1385+ region = toRegion row col
1386+ in
1387+ Report.Report "UNFINISHED CUSTOM TYPE" region [] $
1388+ Code.toSnippet source surroundings (Just region)
1389+ (
1390+ D.reflow $
1391+ "I am partway through parsing a custom type, but I got stuck here:"
1392+ ,
1393+ D.stack
1394+ [ D.reflow $
1395+ "I just saw an equals sign, so I was expecting to see the first variant defined next."
1396+ , customTypeNote
1397+ ]
1398+ )
11741399
11751400
11761401customTypeNote :: D.Doc