on master help sign in
Add remaining syntax messages for type declarations / make EOF message much better
4d4225dEvan Czaplicki
compiler/src/Reporting/Error/Syntax.hs+248−23
@@ -583,19 +583,64 @@ toParseErrorReport source modul =
583 toSpaceReport source space row col
583 toSpaceReport source space row col
584
584
585 ModuleEndOfFile row col ->
585 ModuleEndOfFile row col ->
586− let
586+ case Code.whatIsNext source row col of
587+ Code.Keyword keyword ->
588+ let
587− region = toRegion row col
589+ region = toKeywordRegion row col keyword
588− in
590+ in
589− Report.Report "EXPECTING END OF FILE" region [] $
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 [] $
590− Code.toSnippet source region Nothing
606+ Code.toSnippet source region Nothing
591− (
607+ (
592− D.reflow $
608+ D.reflow $
609+ "I ran into an unexpected symbol:"
610+ ,
611+ D.reflow $
593− "I was not expecting to see anything more here:"
612+ "I was not expecting to see a " ++ op ++ " here. Try deleting it? Maybe\
594− ,
613+ \ I can give a better hint from there?"
595− D.reflow $
614+ )
596− "I think I have read all the declarations in the file and that there is nothing\
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 $
597− \ left to see, so whatever I am running into is confusing me a lot!"
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."
598− )
643+ )
599
644
600 ModuleProblem row col ->
645 ModuleProblem row col ->
601 let
646 let
@@ -1060,7 +1105,7 @@ toTypeAliasReport source typeAlias startRow startCol =
1060 Code.toSnippet source surroundings (Just region)
1105 Code.toSnippet source surroundings (Just region)
1061 (
1106 (
1062 D.reflow $
1107 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:"
1064 ,
1109 ,
1065 D.stack
1110 D.stack
1066 [ D.fillSep $
1111 [ D.fillSep $
@@ -1072,13 +1117,64 @@ toTypeAliasReport source typeAlias startRow startCol =
1072 )
1117 )
1073
1118
1074 AliasEquals row col ->
1119 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+ )
1076
1157
1077 AliasBody tipe row col ->
1158 AliasBody tipe row col ->
1078 toTypeReport source tipe row col
1159 toTypeReport source tipe row col
1079
1160
1080 AliasIndentEquals row col ->
1161 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+ )
1082
1178
1083 AliasIndentBody row col ->
1179 AliasIndentBody row col ->
1084 let
1180 let
@@ -1149,28 +1245,157 @@ toCustomTypeReport source customType startRow startCol =
1149 )
1245 )
1150
1246
1151 CT_Equals row col ->
1247 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+ )
1153
1285
1154 CT_Bar row col ->
1286 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+ )
1156
1303
1157 CT_Variant row col ->
1304 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+ )
1159
1324
1160 CT_VariantArg tipe row col ->
1325 CT_VariantArg tipe row col ->
1161 toTypeReport source tipe row col
1326 toTypeReport source tipe row col
1162
1327
1163 CT_IndentEquals row col ->
1328 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+ )
1165
1345
1166 CT_IndentBar row col ->
1346 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+ )
1168
1363
1169 CT_IndentAfterBar row col ->
1364 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+ )
1171
1381
1172 CT_IndentAfterEquals row col ->
1382 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+ )
1174
1399
1175
1400
1176customTypeNote :: D.Doc
1401customTypeNote :: D.Doc