@@ -69,9 +69,6 @@ data Error
6969 | ModuleNameMismatch ModuleName.Raw (A.Located ModuleName.Raw)
7070 | UnexpectedPort A.Region
7171 | NoPorts A.Region
72− | NoPortsInPackage (A.Located Name.Name)
73− | NoPortModulesInPackage A.Region
74− | NoEffectsOutsideKernel A.Region
7572 | ParseError Module
7673
7774
@@ -520,7 +517,7 @@ toReport source err =
520517 ,
521518 D.stack
522519 [ D.reflow $
523− "I need it to match the file path, so I was expecting to see `"
520+ "I need it to match the file path, so I was expecting it to see `"
524521 ++ ModuleName.toChars expectedName
525522 ++ "` here. Make the following change, and you should be all set!"
526523 , D.indent 4 $
@@ -564,84 +561,10 @@ toReport source err =
564561 ]
565562 )
566563
567− NoPortsInPackage (A.At region _) ->
568− Report.Report "PACKAGES CANNOT HAVE PORTS" region [] $
569− Code.toSnippet source region Nothing
570− (
571− D.reflow $
572− "Packages cannot declare any ports, so I am getting stuck here:"
573− ,
574− D.stack
575− [ D.reflow $
576− "Remove this port declaration."
577− , noteForPortsInPackage
578− ]
579− )
580−
581− NoPortModulesInPackage region ->
582− Report.Report "PACKAGES CANNOT HAVE PORTS" region [] $
583− Code.toSnippet source region Nothing
584− (
585− D.reflow $
586− "Packages cannot declare any ports, so I am getting stuck here:"
587− ,
588− D.stack
589− [ D.fillSep $
590− ["Remove","the",D.cyan "port","keyword","and","I"
591− ,"should","be","able","to","continue."
592− ]
593− , noteForPortsInPackage
594− ]
595− )
596−
597− NoEffectsOutsideKernel region ->
598− Report.Report "INVALID EFFECT MODULE" region [] $
599− Code.toSnippet source region Nothing
600− (
601− D.reflow $
602− "It is not possible to declare an `effect module` outside the @elm organization,\
603− \ so I am getting stuck here:"
604− ,
605− D.stack
606− [ D.reflow $
607− "Switch to a normal module declaration."
608− , D.toSimpleNote $
609− "Effect modules are designed to allow certain core functionality to be\
610− \ defined separately from the compiler. So the @elm organization has access to\
611− \ this so that certain changes, extensions, and fixes can be introduced without\
612− \ needing to release new Elm binaries. For example, we want to make it possible\
613− \ to test effects, but this may require changes to the design of effect modules.\
614− \ By only having them defined in the @elm organization, that kind of design work\
615− \ can proceed much more smoothly."
616− ]
617− )
618−
619564 ParseError modul ->
620565 toParseErrorReport source modul
621566
622567
623−noteForPortsInPackage :: D.Doc
624−noteForPortsInPackage =
625− D.stack
626− [ D.toSimpleNote $
627− "One of the major goals of the package ecosystem is to be completely written\
628− \ in Elm. This means when you install an Elm package, you can be sure you are safe\
629− \ from security issues on install and that you are not going to get any runtime\
630− \ exceptions coming from your new dependency. This design also sets the ecosystem\
631− \ up to target other platforms more easily (like mobile phones, WebAssembly, etc.)\
632− \ since no community code explicitly depends on JavaScript even existing."
633− , D.reflow $
634− "Given that overall goal, allowing ports in packages would lead to some pretty\
635− \ surprising behavior. If ports were allowed in packages, you could install a\
636− \ package but not realize that it brings in an indirect dependency that defines a\
637− \ port. Now you have a program that does not work and the fix is to realize that\
638− \ some JavaScript needs to be added for a dependency you did not even know about.\
639− \ That would be extremely frustrating! \"So why not allow the package author to\
640− \ include the necessary JS code as well?\" Now we are back in conflict with our\
641− \ overall goal to keep all community packages free from runtime exceptions."
642− ]
643−
644−
645568toParseErrorReport :: Code.Source -> Module -> Report.Report
646569toParseErrorReport source modul =
647570 case modul of
@@ -649,9 +572,64 @@ toParseErrorReport source modul =
649572 toSpaceReport source space row col
650573
651574 ModuleBadEnd row col ->
652− if col == 1
653− then toDeclStartReport source row col
654− else toWeirdEndReport source row col
575+ case Code.whatIsNext source row col of
576+ Code.Keyword keyword ->
577+ let
578+ region = toKeywordRegion row col keyword
579+ in
580+ Report.Report "RESERVED WORD" region [] $
581+ Code.toSnippet source region Nothing
582+ (
583+ D.reflow $
584+ "I got stuck on this reserved word:"
585+ ,
586+ D.reflow $
587+ "The name `" ++ keyword ++ "` is reserved, so try using a different name?"
588+ )
589+
590+ Code.Operator op ->
591+ let
592+ region = toKeywordRegion row col op
593+ in
594+ Report.Report "UNEXPECTED SYMBOL" region [] $
595+ Code.toSnippet source region Nothing
596+ (
597+ D.reflow $
598+ "I ran into an unexpected symbol:"
599+ ,
600+ D.reflow $
601+ "I was not expecting to see a " ++ op ++ " here. Try deleting it? Maybe\
602+ \ I can give a better hint from there?"
603+ )
604+
605+ Code.Close term bracket ->
606+ let
607+ region = toRegion row col
608+ in
609+ Report.Report ("UNEXPECTED " ++ map Char.toUpper term) region [] $
610+ Code.toSnippet source region Nothing
611+ (
612+ D.reflow $
613+ "I ran into an unexpected " ++ term ++ ":"
614+ ,
615+ D.reflow $
616+ "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
617+ )
618+
619+ Code.Other ->
620+ let
621+ region = toRegion row col
622+ in
623+ Report.Report "SYNTAX PROBLEM" region [] $
624+ Code.toSnippet source region Nothing
625+ (
626+ D.reflow $
627+ "I got stuck here:"
628+ ,
629+ D.reflow $
630+ "Whatever I am running into is confusing me a lot! Normally I can give fairly\
631+ \ specific hints, but something is really tripping me up this time."
632+ )
655633
656634 ModuleProblem row col ->
657635 let
@@ -797,15 +775,15 @@ toParseErrorReport source modul =
797775 [ D.reflow $
798776 "I am not sure what is going on, but I recommend starting an Elm\
799777 \ file with the following lines:"
800− , D.indent 4 $ D.vcat $
778+ , D.vcat
801779 [ D.fillSep [D.cyan "import","Html"]
802780 , ""
803− , "main ="
804− , " Html.text " <> D.dullyellow "\"Hello!\""
781+ , D.fillSep [D.green "main","="]
782+ , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
805783 ]
806784 , D.reflow $
807− "You should be able to copy those lines directly into your file. Check out the\
808− \ examples at <https://elm-lang.org/examples> for more help getting started!"
785+ "You should be able to copy those lines directly into your file. Check out\
786+ \ some of the examples on https://elm-lang.org for more help getting started!"
809787 , D.toSimpleNote $
810788 "This can also happen when something is indented too much!"
811789 ]
@@ -830,12 +808,11 @@ toParseErrorReport source modul =
830808 , D.indent 4 $ D.vcat $
831809 [ D.fillSep [D.cyan "import","Dict"]
832810 , D.fillSep [D.cyan "import","Maybe"]
833− , D.fillSep [D.cyan "import","Html.Attributes",D.cyan "as","A"]
834− , D.fillSep [D.cyan "import","Json.Decode",D.cyan "exposing","(..)"]
811+ , D.fillSep [D.cyan "import","Html.Attributes"]
812+ , D.fillSep [D.cyan "import","Json.Decode"]
835813 ]
836814 , D.reflow $
837815 "Notice that the module names all start with capital letters. That is required!"
838− , D.reflowLink "Read" "imports" "to learn more."
839816 ]
840817 )
841818
@@ -846,7 +823,7 @@ toParseErrorReport source modul =
846823 let
847824 region = toRegion row col
848825 in
849− Report.Report "EXPECTING IMPORT ALIAS" region [] $
826+ Report.Report "EXECTING IMPORT ALIAS" region [] $
850827 Code.toSnippet source region Nothing
851828 (
852829 D.reflow $
@@ -862,7 +839,6 @@ toParseErrorReport source modul =
862839 ]
863840 , D.reflow $
864841 "Notice that the alias always starts with a capital letter. That is required!"
865− , D.reflowLink "Read" "imports" "to learn more."
866842 ]
867843 )
868844
@@ -925,192 +901,6 @@ toParseErrorReport source modul =
925901
926902
927903
928−-- WEIRD END
929−
930−
931−toWeirdEndReport :: Code.Source -> Row -> Col -> Report.Report
932−toWeirdEndReport source row col =
933− case Code.whatIsNext source row col of
934− Code.Keyword keyword ->
935− let
936− region = toKeywordRegion row col keyword
937− in
938− Report.Report "RESERVED WORD" region [] $
939− Code.toSnippet source region Nothing
940− (
941− D.reflow $
942− "I got stuck on this reserved word:"
943− ,
944− D.reflow $
945− "The name `" ++ keyword ++ "` is reserved, so try using a different name?"
946− )
947−
948− Code.Operator op ->
949− let
950− region = toKeywordRegion row col op
951− in
952− Report.Report "UNEXPECTED SYMBOL" region [] $
953− Code.toSnippet source region Nothing
954− (
955− D.reflow $
956− "I ran into an unexpected symbol:"
957− ,
958− D.reflow $
959− "I was not expecting to see a " ++ op ++ " here. Try deleting it? Maybe\
960− \ I can give a better hint from there?"
961− )
962−
963− Code.Close term bracket ->
964− let
965− region = toRegion row col
966− in
967− Report.Report ("UNEXPECTED " ++ map Char.toUpper term) region [] $
968− Code.toSnippet source region Nothing
969− (
970− D.reflow $
971− "I ran into an unexpected " ++ term ++ ":"
972− ,
973− D.reflow $
974− "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
975− )
976−
977− Code.Lower c cs ->
978− let
979− region = toKeywordRegion row col (c:cs)
980− in
981− Report.Report "UNEXPECTED NAME" region [] $
982− Code.toSnippet source region Nothing
983− (
984− D.reflow $
985− "I got stuck on this name:"
986− ,
987− D.reflow $
988− "It is confusing me a lot! Normally I can give fairly specific hints, but\
989− \ something is really tripping me up this time."
990− )
991−
992− Code.Upper c cs ->
993− let
994− region = toKeywordRegion row col (c:cs)
995− in
996− Report.Report "UNEXPECTED NAME" region [] $
997− Code.toSnippet source region Nothing
998− (
999− D.reflow $
1000− "I got stuck on this name:"
1001− ,
1002− D.reflow $
1003− "It is confusing me a lot! Normally I can give fairly specific hints, but\
1004− \ something is really tripping me up this time."
1005− )
1006−
1007− Code.Other maybeChar ->
1008− let
1009− region = toRegion row col
1010− in
1011− case maybeChar of
1012− Just ';' ->
1013− Report.Report "UNEXPECTED SEMICOLON" region [] $
1014− Code.toSnippet source region Nothing
1015− (
1016− D.reflow $
1017− "I got stuck on this semicolon:"
1018− ,
1019− D.stack
1020− [ D.reflow $ "Try removing it?"
1021− , D.toSimpleNote $
1022− "Some languages require semicolons at the end of each statement. These are\
1023− \ often called C-like languages, and they usually share a lot of language design\
1024− \ choices. (E.g. side-effects, for loops, etc.) Elm manages effects with commands\
1025− \ and subscriptions instead, so there is no special syntax for \"statements\" and\
1026− \ therefore no need to use semicolons to separate them. I think this will make\
1027− \ more sense as you work through <https://guide.elm-lang.org> though!"
1028− ]
1029− )
1030−
1031− Just ',' ->
1032− Report.Report "UNEXPECTED COMMA" region [] $
1033− Code.toSnippet source region Nothing
1034− (
1035− D.reflow $
1036− "I got stuck on this comma:"
1037− ,
1038− D.stack
1039− [ D.reflow $
1040− "I do not think I am parsing a list or tuple right now. Try deleting the comma?"
1041− , D.toSimpleNote $
1042− "If this is supposed to be part of a list, the problem may be a bit earlier.\
1043− \ Perhaps the opening [ is missing? Or perhaps some value in the list has an extra\
1044− \ closing ] that is making me think the list ended earlier? The same kinds of\
1045− \ things could be going wrong if this is supposed to be a tuple."
1046− ]
1047− )
1048−
1049− Just '`' ->
1050− Report.Report "UNEXPECTED CHARACTER" region [] $
1051− Code.toSnippet source region Nothing
1052− (
1053− D.reflow $
1054− "I got stuck on this character:"
1055− ,
1056− D.stack
1057− [ D.reflow $
1058− "It is not used for anything in Elm syntax. It is used for multi-line strings in\
1059− \ some languages though, so if you want a string that spans multiple lines, you\
1060− \ can use Elm's multi-line string syntax like this:"
1061− , D.dullyellow $ D.indent 4 $ D.vcat $
1062− [ "\"\"\""
1063− , "# Multi-line Strings"
1064− , ""
1065− , "- start with triple double quotes"
1066− , "- write whatever you want"
1067− , "- no need to escape newlines or double quotes"
1068− , "- end with triple double quotes"
1069− , "\"\"\""
1070− ]
1071− , D.reflow $
1072− "Otherwise I do not know what is going on! Try removing the character?"
1073− ]
1074− )
1075−
1076− Just '$' ->
1077− Report.Report "UNEXPECTED SYMBOL" region [] $
1078− Code.toSnippet source region Nothing
1079− (
1080− D.reflow $
1081− "I got stuck on this dollar sign:"
1082− ,
1083− D.reflow $
1084− "It is not used for anything in Elm syntax. Are you coming from a language where\
1085− \ dollar signs can be used in variable names? If so, try a name that (1) starts\
1086− \ with a letter and (2) only contains letters, numbers, and underscores."
1087− )
1088−
1089− Just c | elem c ['#','@','!','%','~'] ->
1090− Report.Report "UNEXPECTED SYMBOL" region [] $
1091− Code.toSnippet source region Nothing
1092− (
1093− D.reflow $
1094− "I got stuck on this symbol:"
1095− ,
1096− D.reflow $
1097− "It is not used for anything in Elm syntax. Try removing it?"
1098− )
1099−
1100− _ ->
1101− Report.Report "SYNTAX PROBLEM" region [] $
1102− Code.toSnippet source region Nothing
1103− (
1104− D.reflow $
1105− "I got stuck here:"
1106− ,
1107− D.reflow $
1108− "Whatever I am running into is confusing me a lot! Normally I can give fairly\
1109− \ specific hints, but something is really tripping me up this time."
1110− )
1111−
1112−
1113−
1114904-- IMPORTS
1115905
1116906
@@ -1136,7 +926,6 @@ toImportReport source row col =
1136926 ]
1137927 , D.reflow $
1138928 "You are probably trying to import a different module, but try to make it look like one of these examples!"
1139− , D.reflowLink "Read" "imports" "to learn more."
1140929 ]
1141930 )
1142931
@@ -1443,7 +1232,106 @@ toDeclarationsReport :: Code.Source -> Decl -> Report.Report
14431232toDeclarationsReport source decl =
14441233 case decl of
14451234 DeclStart row col ->
1446− toDeclStartReport source row col
1235+ case Code.whatIsNext source row col of
1236+ Code.Close term bracket ->
1237+ let
1238+ region = toRegion row col
1239+ in
1240+ Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
1241+ Code.toSnippet source region Nothing
1242+ (
1243+ D.reflow $
1244+ "I was not expecting to see a " ++ term ++ " here:"
1245+ , D.reflow $
1246+ "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
1247+ )
1248+
1249+ Code.Keyword keyword ->
1250+ let
1251+ region = toKeywordRegion row col keyword
1252+ in
1253+ Report.Report "RESERVED WORD" region [] $
1254+ Code.toSnippet source region Nothing
1255+ (
1256+ D.reflow $
1257+ "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
1258+ ,
1259+ case keyword of
1260+ "import" ->
1261+ D.reflow $
1262+ "It is reserved for declaring imports at the top of your module. If you want\
1263+ \ another import, try moving it up top with the other imports. If you want to\
1264+ \ define a value or function, try changing the name to something else!"
1265+
1266+ "case" ->
1267+ D.stack
1268+ [ D.reflow $
1269+ "It is reserved for writing `case` expressions. Try using a different name?"
1270+ , D.toSimpleNote $
1271+ "If you are trying to write a `case` expression, it needs to be part of a\
1272+ \ definition. So you could write something like this instead:"
1273+ , D.vcat $
1274+ [ D.indent 0 $ D.fillSep [D.green "getWidth","maybeWidth","="]
1275+ , D.indent 2 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
1276+ , D.indent 4 $ D.fillSep [D.blue "Just","width","->"]
1277+ , D.indent 6 $ D.fillSep ["width","+",D.dullyellow "200"]
1278+ , ""
1279+ , D.indent 4 $ D.fillSep [D.blue "Nothing","->"]
1280+ , D.indent 6 $ D.fillSep [D.dullyellow "400"]
1281+ ]
1282+ , D.reflow $
1283+ "This defines a `getWidth` function that we can use elsewhere in our program."
1284+ ]
1285+
1286+ "if" ->
1287+ D.stack
1288+ [ D.reflow $
1289+ "It is reserved for writing `if` expressions. Try using a different name?"
1290+ , D.toSimpleNote $
1291+ "If you are trying to write an `if` expression, it needs to be part of a\
1292+ \ definition. So you could write something like this instead:"
1293+ , D.vcat $
1294+ [ D.indent 0 $ D.fillSep [D.green "reviewPowerLevel","powerLevel","="]
1295+ , D.indent 2 $ D.fillSep $
1296+ [D.cyan "if","powerLevel",">",D.dullyellow "9000"
1297+ ,D.cyan "then",D.dullyellow "\"OVER 9000!!!\""
1298+ ,D.cyan "else",D.dullyellow "\"not bad\""
1299+ ]
1300+ ]
1301+ , D.reflow $
1302+ "This defines a `reviewPowerLevel` function that we can use elsewhere in our program."
1303+ ]
1304+
1305+ _ ->
1306+ D.reflow $
1307+ "It is a reserved word. Try changing the name to something else?"
1308+ )
1309+
1310+ _ ->
1311+ let
1312+ region = toRegion row col
1313+ in
1314+ Report.Report "SYNTAX PROBLEM" region [] $
1315+ Code.toSnippet source region Nothing
1316+ (
1317+ D.reflow $
1318+ "I was expecting to see a new declaration here:"
1319+ ,
1320+ D.stack
1321+ [ D.reflow $
1322+ "I am not sure what is going wrong exactly, but here are a couple valid\
1323+ \ declarations for reference:"
1324+ , D.vcat
1325+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
1326+ , D.fillSep [D.green "add","x","y","="]
1327+ , D.fillSep [" ","x","+","y"]
1328+ ]
1329+ , D.fillSep [D.cyan "type",D.green "User","=","Anonymous","|","LoggedIn String"]
1330+ , D.reflow $
1331+ "Note that all declarations start with lower-case letters in Elm. Capitalization\
1332+ \ makes a difference, so be consious of that if you are working from examples!"
1333+ ]
1334+ )
14471335
14481336 DeclSpace space row col ->
14491337 toSpaceReport source space row col
@@ -1473,165 +1361,6 @@ toDeclarationsReport source decl =
14731361 )
14741362
14751363
1476−toDeclStartReport :: Code.Source -> Row -> Col -> Report.Report
1477−toDeclStartReport source row col =
1478− case Code.whatIsNext source row col of
1479− Code.Close term bracket ->
1480− let
1481− region = toRegion row col
1482− in
1483− Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
1484− Code.toSnippet source region Nothing
1485− (
1486− D.reflow $
1487− "I was not expecting to see a " ++ term ++ " here:"
1488− , D.reflow $
1489− "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
1490− )
1491−
1492− Code.Keyword keyword ->
1493− let
1494− region = toKeywordRegion row col keyword
1495− in
1496− Report.Report "RESERVED WORD" region [] $
1497− Code.toSnippet source region Nothing
1498− (
1499− D.reflow $
1500− "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
1501− ,
1502− case keyword of
1503− "import" ->
1504− D.reflow $
1505− "It is reserved for declaring imports at the top of your module. If you want\
1506− \ another import, try moving it up top with the other imports. If you want to\
1507− \ define a value or function, try changing the name to something else!"
1508−
1509− "case" ->
1510− D.stack
1511− [ D.reflow $
1512− "It is reserved for writing `case` expressions. Try using a different name?"
1513− , D.toSimpleNote $
1514− "If you are trying to write a `case` expression, it needs to be part of a\
1515− \ definition. So you could write something like this instead:"
1516− , D.indent 4 $ D.vcat $
1517− [ D.indent 0 $ D.fillSep ["getWidth","maybeWidth","="]
1518− , D.indent 2 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
1519− , D.indent 4 $ D.fillSep [D.blue "Just","width","->"]
1520− , D.indent 6 $ D.fillSep ["width","+",D.dullyellow "200"]
1521− , ""
1522− , D.indent 4 $ D.fillSep [D.blue "Nothing","->"]
1523− , D.indent 6 $ D.fillSep [D.dullyellow "400"]
1524− ]
1525− , D.reflow $
1526− "This defines a `getWidth` function that you can use elsewhere in your program."
1527− ]
1528−
1529− "if" ->
1530− D.stack
1531− [ D.reflow $
1532− "It is reserved for writing `if` expressions. Try using a different name?"
1533− , D.toSimpleNote $
1534− "If you are trying to write an `if` expression, it needs to be part of a\
1535− \ definition. So you could write something like this instead:"
1536− , D.indent 4 $ D.vcat $
1537− [ "greet name ="
1538− , D.fillSep $
1539− [" "
1540− ,D.cyan "if","name","==",D.dullyellow "\"Abraham Lincoln\""
1541− ,D.cyan "then",D.dullyellow "\"Greetings Mr. President.\""
1542− ,D.cyan "else",D.dullyellow "\"Hey!\""
1543− ]
1544− ]
1545− , D.reflow $
1546− "This defines a `reviewPowerLevel` function that you can use elsewhere in your program."
1547− ]
1548−
1549− _ ->
1550− D.reflow $
1551− "It is a reserved word. Try changing the name to something else?"
1552− )
1553−
1554− Code.Upper c cs ->
1555− let
1556− region = toRegion row col
1557− in
1558− Report.Report "UNEXPECTED CAPITAL LETTER" region [] $
1559− Code.toSnippet source region Nothing
1560− (
1561− D.reflow $
1562− "Declarations always start with a lower-case letter, so I am getting stuck here:"
1563− ,
1564− D.stack
1565− [ D.fillSep $
1566− ["Try","a","name","like"
1567− ,D.green (D.fromChars (Char.toLower c : cs))
1568− ,"instead?"
1569− ]
1570− , D.toSimpleNote $
1571− "Here are a couple valid declarations for reference:"
1572− , D.indent 4 $ D.vcat $
1573− [ "greet : String -> String"
1574− , "greet name ="
1575− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1576− , ""
1577− , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1578− ]
1579− , D.reflow $
1580− "Notice that they always start with a lower-case letter. Capitalization matters!"
1581− ]
1582− )
1583−
1584− Code.Other (Just char) | elem char ['(', '{', '[', '+', '-', '*', '/', '^', '&', '|', '"', '\'', '!', '@', '#', '$', '%'] ->
1585− let
1586− region = toRegion row col
1587− in
1588− Report.Report "UNEXPECTED SYMBOL" region [] $
1589− Code.toSnippet source region Nothing
1590− (
1591− D.reflow $
1592− "I am getting stuck because this line starts with the " ++ [char] ++ " symbol:"
1593− ,
1594− D.stack
1595− [ D.reflow $
1596− "When a line has no spaces at the beginning, I expect it to be a declaration like one of these:"
1597− , D.indent 4 $ D.vcat $
1598− [ "greet : String -> String"
1599− , "greet name ="
1600− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1601− , ""
1602− , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1603− ]
1604− , D.reflow $
1605− "If this is not supposed to be a declaration, try adding some spaces before it?"
1606− ]
1607− )
1608−
1609− _ ->
1610− let
1611− region = toRegion row col
1612− in
1613− Report.Report "WEIRD DECLARATION" region [] $
1614− Code.toSnippet source region Nothing
1615− (
1616− D.reflow $
1617− "I am trying to parse a declaration, but I am getting stuck here:"
1618− ,
1619− D.stack
1620− [ D.reflow $
1621− "When a line has no spaces at the beginning, I expect it to be a declaration like one of these:"
1622− , D.indent 4 $ D.vcat $
1623− [ "greet : String -> String"
1624− , "greet name ="
1625− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1626− , ""
1627− , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1628− ]
1629− , D.reflow $
1630− "Try to make your declaration look like one of those? Or if this is not\
1631− \ supposed to be a declaration, try adding some spaces before it?"
1632− ]
1633− )
1634−
16351364
16361365-- PORT
16371366
@@ -1758,7 +1487,7 @@ toPortReport source port_ startRow startCol =
17581487 [ D.reflow $
17591488 "I was expecting to see a type next. Here are examples of outgoing and\
17601489 \ incoming ports for reference:"
1761− , D.indent 4 $ D.vcat $
1490+ , D.vcat
17621491 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
17631492 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
17641493 ]
@@ -1777,7 +1506,7 @@ portNote =
17771506 D.stack
17781507 [ D.toSimpleNote $
17791508 "Here are some example `port` declarations for reference:"
1780− , D.indent 4 $ D.vcat $
1509+ , D.vcat
17811510 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
17821511 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
17831512 ]
@@ -1907,7 +1636,7 @@ toTypeAliasReport source typeAlias startRow startCol =
19071636 ,
19081637 D.stack
19091638 [ D.reflow $
1910− "I was expecting to see a type variable or an equals sign next."
1639+ "I was expecting to see a type variable or an an equals sign next."
19111640 , typeAliasNote
19121641 ]
19131642 )
@@ -1928,7 +1657,7 @@ toTypeAliasReport source typeAlias startRow startCol =
19281657 ,
19291658 D.stack
19301659 [ D.reflow $
1931− "I was expecting to see a type variable or an equals sign next."
1660+ "I was expecting to see a type variable or an an equals sign next."
19321661 , typeAliasNote
19331662 ]
19341663 )
@@ -1960,8 +1689,8 @@ typeAliasNote =
19601689 [ D.toSimpleNote $
19611690 "Here is an example of a valid `type alias` for reference:"
19621691 , D.vcat $
1963− [ D.indent 4 $ D.fillSep [D.cyan "type",D.cyan "alias","Person","="]
1964− , D.indent 6 $ D.vcat $
1692+ [ D.indent 0 $ D.fillSep [D.cyan "type",D.cyan "alias",D.green "Person","="]
1693+ , D.indent 2 $ D.vcat $
19651694 ["{ name : String"
19661695 ,", age : Int"
19671696 ,", height : Float"
@@ -2035,7 +1764,7 @@ toCustomTypeReport source customType startRow startCol =
20351764 ,
20361765 D.stack
20371766 [ D.reflow $
2038− "I was expecting to see a type variable or an equals sign next."
1767+ "I was expecting to see a type variable or an an equals sign next."
20391768 , customTypeNote
20401769 ]
20411770 )
@@ -2095,7 +1824,7 @@ toCustomTypeReport source customType startRow startCol =
20951824 ,
20961825 D.stack
20971826 [ D.reflow $
2098− "I was expecting to see a type variable or an equals sign next."
1827+ "I was expecting to see a type variable or an an equals sign next."
20991828 , customTypeNote
21001829 ]
21011830 )
@@ -2161,10 +1890,10 @@ customTypeNote =
21611890 [ D.toSimpleNote $
21621891 "Here is an example of a valid `type` declaration for reference:"
21631892 , D.vcat $
2164− [ D.indent 4 $ D.fillSep [D.cyan "type","Status"]
2165− , D.indent 6 $ D.fillSep ["=","Failure"]
2166− , D.indent 6 $ D.fillSep ["|","Waiting"]
2167− , D.indent 6 $ D.fillSep ["|","Success","String"]
1893+ [ D.indent 0 $ D.fillSep [D.cyan "type",D.green "Status"]
1894+ , D.indent 2 $ D.fillSep ["=","Failure"]
1895+ , D.indent 2 $ D.fillSep ["|","Waiting"]
1896+ , D.indent 2 $ D.fillSep ["|","Success","String"]
21681897 ]
21691898 , D.reflow $
21701899 "This defines a new `Status` type with three variants. This could be useful if\
@@ -2193,57 +1922,13 @@ toDeclDefReport source name declDef startRow startCol =
21931922 region = toKeywordRegion row col keyword
21941923 in
21951924 Report.Report "RESERVED WORD" region [] $
2196− Code.toSnippet source surroundings (Just region)
2197− (
2198− D.fillSep
2199− ["The","name"
2200− ,"`" <> D.cyan (D.fromChars keyword) <> "`"
2201− ,"is","reserved","in","Elm,","so","it","cannot"
2202− ,"be","used","as","an","argument","here:"
2203− ]
2204− ,
2205− D.stack
2206− [ D.reflow $
2207− "Try renaming it to something else."
2208− , case keyword of
2209− "as" ->
2210− D.toFancyNote
2211− ["This","keyword","is","reserved","for","pattern","matches","like"
2212− ,"((x,y)",D.cyan "as","point)","where","you","want","to","name","a","tuple","and"
2213− ,"the","values","it","contains."
2214− ]
2215−
2216− _ ->
2217− D.toSimpleNote $
2218− "The `" ++ keyword ++ "` keyword has a special meaning in Elm, so it can only be used in certain situations."
2219− ]
2220− )
2221−
2222− Code.Operator "->" ->
2223− let
2224− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2225− region = toWiderRegion row col 2
2226− in
2227− Report.Report "MISSING COLON?" region [] $
22281925 Code.toSnippet source surroundings (Just region)
22291926 (
22301927 D.reflow $
2231− "I was not expecting to see an arrow here:"
1928+ "It looks like you are trying to use `" ++ keyword ++ "` as an argument:"
22321929 ,
2233− D.stack
2234− [ D.fillSep
2235− ["This","usually","means","a",D.green ":","is","missing","a","bit","earlier","in"
2236− ,"a","type","annotation.","It","could","be","something","else","though,","so"
2237− ,"here","is","a","valid","definition","for","reference:"
2238− ]
2239− , D.indent 4 $ D.vcat $
2240− [ "greet : String -> String"
2241− , "greet name ="
2242− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
2243− ]
2244− , D.reflow $
2245− "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
2246− ]
1930+ D.reflow $
1931+ "This is a reserved word! Try using some other name?"
22471932 )
22481933
22491934 Code.Operator op ->
@@ -2261,10 +1946,10 @@ toDeclDefReport source name declDef startRow startCol =
22611946 [ D.reflow $
22621947 "I am not sure what is going wrong exactly, so here is a valid\
22631948 \ definition (with an optional type annotation) for reference:"
2264− , D.indent 4 $ D.vcat $
2265− [ "greet : String -> String"
2266− , "greet name ="
2267− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1949+ , D.vcat
1950+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
1951+ , D.fillSep [D.green "add","x","y","="]
1952+ , D.fillSep [" ","x","+","y"]
22681953 ]
22691954 , D.reflow $
22701955 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -2286,10 +1971,10 @@ toDeclDefReport source name declDef startRow startCol =
22861971 [ D.reflow $
22871972 "I am not sure what is going wrong exactly, so here is a valid\
22881973 \ definition (with an optional type annotation) for reference:"
2289− , D.indent 4 $ D.vcat $
2290− [ "greet : String -> String"
2291− , "greet name ="
2292− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1974+ , D.vcat
1975+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
1976+ , D.fillSep [D.green "add","x","y","="]
1977+ , D.fillSep [" ","x","+","y"]
22931978 ]
22941979 , D.reflow $
22951980 "Try to use that format!"
@@ -2404,10 +2089,10 @@ declDefNote =
24042089 D.stack
24052090 [ D.reflow $
24062091 "Here is a valid definition (with a type annotation) for reference:"
2407− , D.indent 4 $ D.vcat $
2408− [ "greet : String -> String"
2409− , "greet name ="
2410− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
2092+ , D.vcat
2093+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2094+ , D.fillSep [D.green "add","x","y","="]
2095+ , D.fillSep [" ","x","+","y"]
24112096 ]
24122097 , D.reflow $
24132098 "The top line (called a \"type annotation\") is optional. You can leave it off\
@@ -2519,40 +2204,25 @@ toExprReport source context expr startRow startCol =
25192204 )
25202205
25212206 OperatorRight op row col ->
2522− let
2523− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2524− region = toRegion row col
2525− isMath = elem op ["-","+","*","/","^"]
2526− in
2207+ let region = toRegion row col in
25272208 Report.Report "MISSING EXPRESSION" region [] $
2528− Code.toSnippet source surroundings (Just region)
2209+ Code.toSnippet source region Nothing
25292210 (
25302211 D.reflow $
2531− "I just saw a " ++ Name.toChars op ++ " "
2532− ++ (if isMath then "sign" else "operator")
2533− ++ ", so I am getting stuck here:"
2212+ "I was expecting to see an expression after this " ++ Name.toChars op ++ " operator:"
25342213 ,
2535− if isMath then
2536− D.fillSep
2537− ["I","was","expecting","to","see","an","expression","next."
2538− ,"Something","like",D.dullyellow "42","or",D.dullyellow "1000"
2539− ,"that","makes","sense","with","a",D.fromName op,"sign."
2540− ]
2541− else if op == "&&" || op == "||" then
2542− D.fillSep
2543− ["I","was","expecting","to","see","an","expression","next."
2544− ,"Something","like",D.dullyellow "True","or",D.dullyellow "False"
2545− ,"that","makes","sense","with","boolean","logic."
2546− ]
2547− else if op == "|>" then
2548− D.reflow $
2549− "I was expecting to see a function next."
2550− else if op == "<|" then
2551− D.reflow $
2552− "I was expecting to see an argument next."
2553− else
2554− D.reflow $
2555− "I was expecting to see an expression next."
2214+ D.stack
2215+ [ D.fillSep $
2216+ ["You","can","just","put","anything","for","now,","like"
2217+ ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
2218+ ,"Once","there","is","something","there,","I","can","probably"
2219+ ,"give","a","more","specific","hint!"
2220+ ]
2221+ , D.toSimpleNote $
2222+ "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
2223+ \ Or if I run into operators in unexpected spots. Point is, there are a\
2224+ \ couple ways I can get confused and give sort of weird advice!"
2225+ ]
25562226 )
25572227
25582228 OperatorReserved operator row col ->
@@ -2591,7 +2261,7 @@ toExprReport source context expr startRow startCol =
25912261 ,"give","a","more","specific","hint!"
25922262 ]
25932263 , D.toSimpleNote $
2594− "This can also happen if I run into reserved words like `let` or `as` unexpectedly.\
2264+ "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
25952265 \ Or if I run into operators in unexpected spots. Point is, there are a\
25962266 \ couple ways I can get confused and give sort of weird advice!"
25972267 ]
@@ -2740,15 +2410,17 @@ toStringReport source string row col =
27402410 , D.toSimpleNote $
27412411 "For a string that spans multiple lines, you can use the multi-line string\
27422412 \ syntax like this:"
2743− , D.dullyellow $ D.indent 4 $ D.vcat $
2744− [ "\"\"\""
2745− , "# Multi-line Strings"
2746− , ""
2747− , "- start with triple double quotes"
2748− , "- write whatever you want"
2749− , "- no need to escape newlines or double quotes"
2750− , "- end with triple double quotes"
2751− , "\"\"\""
2413+ , D.vcat
2414+ [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
2415+ , mempty
2416+ , D.dullyellow "# Multi-line Strings"
2417+ , mempty
2418+ , D.dullyellow "- start with triple double quotes"
2419+ , D.dullyellow "- write whatever you want"
2420+ , D.dullyellow "- no need to escape newlines or double quotes"
2421+ , D.dullyellow "- end with triple double quotes"
2422+ , mempty
2423+ , D.dullyellow "\"\"\""
27522424 ]
27532425 ]
27542426 )
@@ -2767,15 +2439,17 @@ toStringReport source string row col =
27672439 [ D.reflow "Add a \"\"\" somewhere after this to end the string."
27682440 , D.toSimpleNote $
27692441 "Here is a valid multi-line string for reference:"
2770− , D.dullyellow $ D.indent 4 $ D.vcat $
2771− [ "\"\"\""
2772− , "# Multi-line Strings"
2773− , ""
2774− , "- start with triple double quotes"
2775− , "- write whatever you want"
2776− , "- no need to escape newlines or double quotes"
2777− , "- end with triple double quotes"
2778− , "\"\"\""
2442+ , D.vcat
2443+ [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
2444+ , mempty
2445+ , D.dullyellow "# Multi-line Strings"
2446+ , mempty
2447+ , D.dullyellow "- start with triple double quotes"
2448+ , D.dullyellow "- write whatever you want"
2449+ , D.dullyellow "- no need to escape newlines or double quotes"
2450+ , D.dullyellow "- end with triple double quotes"
2451+ , mempty
2452+ , D.dullyellow "\"\"\""
27792453 ]
27802454 ]
27812455 )
@@ -3027,7 +2701,7 @@ toOperatorReport source context operator row col =
30272701 ,
30282702 D.stack
30292703 [ D.reflow $
3030− "It makes sense to see arrows around here, so I suspect it is something earlier. Maybe this pattern is indented a bit farther than the previous patterns?"
2704+ "It makes sense to see arrows around here, so I suspect it is something earlier."
30312705 , noteForCaseIndentError
30322706 ]
30332707 )
@@ -3035,15 +2709,11 @@ toOperatorReport source context operator row col =
30352709 else
30362710 (
30372711 D.reflow $
3038− "I was partway through parsing an expression when I got stuck on this arrow:"
2712+ "I was not expecting an arrow here:"
30392713 ,
3040− D.stack
3041− [ "Arrows should only appear in `case` expressions and anonymous functions.\n\
3042− \Maybe it was supposed to be a > sign instead?"
3043− , D.toSimpleNote $
3044− "The syntax for anonymous functions is (\\x -> x + 1) so the arguments all appear\
3045− \ after the backslash and before the arrow. Maybe a backslash is missing earlier?"
3046− ]
2714+ D.reflow $
2715+ "Arrows should only appear in `case` expressions and anonymous functions. Maybe\
2716+ \ you want > or >= instead?"
30472717 )
30482718
30492719 BadEquals ->
@@ -3170,7 +2840,7 @@ toLetReport source context let_ startRow startCol =
31702840 , D.toSimpleNote $
31712841 "This can also happen if you are trying to define another value within the `let` but\
31722842 \ it is not indented enough. Make sure each definition has exactly the same amount of\
3173− \ spaces before it. They should line up exactly!"
2843+ \ spaces before it. The should line up exactly!"
31742844 ]
31752845 )
31762846
@@ -3240,8 +2910,8 @@ toUnfinishLetReport source row col startRow startCol message =
32402910 [ message
32412911 , D.toSimpleNote $
32422912 "Here is an example with a valid `let` expression for reference:"
3243− , D.indent 4 $ D.vcat $
3244− [ D.indent 0 $ D.fillSep ["viewPerson","person","="]
2913+ , D.vcat $
2914+ [ D.indent 0 $ D.fillSep [D.green "viewPerson","person","="]
32452915 , D.indent 2 $ D.fillSep [D.cyan "let"]
32462916 , D.indent 4 $ D.fillSep ["fullName","="]
32472917 , D.indent 6 $ D.fillSep ["person.firstName","++",D.dullyellow "\" \"","++","person.lastName"]
@@ -3316,57 +2986,13 @@ toLetDefReport source name def startRow startCol =
33162986 region = toKeywordRegion row col keyword
33172987 in
33182988 Report.Report "RESERVED WORD" region [] $
3319− Code.toSnippet source surroundings (Just region)
3320− (
3321− D.fillSep
3322− ["The","name"
3323− ,"`" <> D.cyan (D.fromChars keyword) <> "`"
3324− ,"is","reserved","in","Elm,","so","it","cannot"
3325− ,"be","used","as","an","argument","here:"
3326− ]
3327− ,
3328− D.stack
3329− [ D.reflow $
3330− "Try renaming it to something else."
3331− , case keyword of
3332− "as" ->
3333− D.toFancyNote
3334− ["This","keyword","is","reserved","for","pattern","matches","like"
3335− ,"((x,y)",D.cyan "as","point)","where","you","want","to","name","a","tuple","and"
3336− ,"the","values","it","contains."
3337− ]
3338−
3339− _ ->
3340− D.toSimpleNote $
3341− "The `" ++ keyword ++ "` keyword has a special meaning in Elm, so it can only be used in certain situations."
3342− ]
3343− )
3344−
3345− Code.Operator "->" ->
3346− let
3347− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3348− region = toWiderRegion row col 2
3349− in
3350− Report.Report "MISSING COLON?" region [] $
33512989 Code.toSnippet source surroundings (Just region)
33522990 (
33532991 D.reflow $
3354− "I was not expecting to see an arrow here:"
2992+ "It looks like you are trying to use `" ++ keyword ++ "` as an argument:"
33552993 ,
3356− D.stack
3357− [ D.fillSep
3358− ["This","usually","means","a",D.green ":","is","missing","a","bit","earlier","in"
3359− ,"a","type","annotation.","It","could","be","something","else","though,","so"
3360− ,"here","is","a","valid","definition","for","reference:"
3361− ]
3362− , D.indent 4 $ D.vcat $
3363− [ "greet : String -> String"
3364− , "greet name ="
3365− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
3366− ]
3367− , D.reflow $
3368− "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
3369− ]
2994+ D.reflow $
2995+ "This is a reserved word! Try using some other name?"
33702996 )
33712997
33722998 Code.Operator op ->
@@ -3384,10 +3010,10 @@ toLetDefReport source name def startRow startCol =
33843010 [ D.reflow $
33853011 "I am not sure what is going wrong exactly, so here is a valid\
33863012 \ definition (with an optional type annotation) for reference:"
3387− , D.indent 4 $ D.vcat $
3388− [ "greet : String -> String"
3389− , "greet name ="
3390− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
3013+ , D.vcat
3014+ [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3015+ , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3016+ , D.indent 6 $ D.fillSep ["x","+","y"]
33913017 ]
33923018 , D.reflow $
33933019 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -3409,10 +3035,10 @@ toLetDefReport source name def startRow startCol =
34093035 [ D.reflow $
34103036 "I am not sure what is going wrong exactly, so here is a valid\
34113037 \ definition (with an optional type annotation) for reference:"
3412− , D.indent 4 $ D.vcat $
3413− [ "greet : String -> String"
3414− , "greet name ="
3415− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
3038+ , D.vcat
3039+ [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3040+ , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3041+ , D.indent 4 $ D.fillSep ["x","+","y"]
34163042 ]
34173043 , D.reflow $
34183044 "Try to use that format!"
@@ -3502,10 +3128,10 @@ defNote =
35023128 D.stack
35033129 [ D.reflow $
35043130 "Here is a valid definition (with a type annotation) for reference:"
3505− , D.indent 4 $ D.vcat $
3506− [ "greet : String -> String"
3507− , "greet name ="
3508− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
3131+ , D.vcat
3132+ [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3133+ , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3134+ , D.indent 6 $ D.fillSep ["x","+","y"]
35093135 ]
35103136 , D.reflow $
35113137 "The top line (called a \"type annotation\") is optional. You can leave it off\
@@ -3764,9 +3390,8 @@ noteForCaseIndentError =
37643390 , D.indent 8 $ D.fillSep [D.dullyellow "400"]
37653391 ]
37663392 , D.reflow $
3767− "Notice the indentation! Patterns are aligned with each other. Same indentation.\
3768− \ The expressions after each arrow are all indented a bit more than the patterns.\
3769− \ That is important!"
3393+ "Notice the indentation! Each pattern is aligned, and each branch is indented\
3394+ \ a bit more than the corresponding pattern. That is important!"
37703395 ]
37713396
37723397
@@ -3918,43 +3543,23 @@ toIfReport source context if_ startRow startCol =
39183543 )
39193544
39203545 IfIndentElse row col ->
3921− case Code.nextLineStartsWithKeyword "else" source row of
3922− Just (elseRow, elseCol) ->
3923− let
3924− surroundings = A.Region (A.Position startRow startCol) (A.Position elseRow elseCol)
3925− region = toWiderRegion elseRow elseCol 4
3926− in
3927− Report.Report "WEIRD ELSE BRANCH" region [] $
3928− Code.toSnippet source surroundings (Just region)
3929− (
3930− D.reflow $
3931− "I was partway through an `if` expression when I got stuck here:"
3932− ,
3933− D.fillSep $
3934− ["I","think","this",D.cyan "else","keyword","needs","to","be","indented","more."
3935− ,"Try","adding","some","spaces","before","it."
3936− ]
3937− )
3938−
3939− Nothing ->
3940− let
3941− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3942− region = toRegion row col
3943− in
3944− Report.Report "UNFINISHED IF" region [] $
3945− Code.toSnippet source surroundings (Just region)
3946− (
3947− D.reflow $
3948− "I was expecting to see an `else` branch after this:"
3949− ,
3950− D.stack
3951− [ D.fillSep
3952− ["I","know","what","to","do","when","the","condition","is","True,"
3953− ,"but","what","happens","when","it","is","False?"
3954− ,"Add","an",D.cyan "else","branch","to","handle","that","scenario!"
3955− ]
3956− ]
3957− )
3546+ let
3547+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3548+ region = toRegion row col
3549+ in
3550+ Report.Report "UNFINISHED IF" region [] $
3551+ Code.toSnippet source surroundings (Just region)
3552+ (
3553+ D.reflow $
3554+ "I was expecting to see an `else` branch after this:"
3555+ ,
3556+ D.stack
3557+ [ D.reflow $
3558+ "I know what to do when the condition is `True`, but not when it is `False`."
3559+ , D.fillSep
3560+ ["Add","an",D.cyan "else","branch","to","handle","that","scenario!"]
3561+ ]
3562+ )
39583563
39593564
39603565
@@ -3987,22 +3592,15 @@ toRecordReport source context record startRow startCol =
39873592 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
39883593 region = toRegion row col
39893594 in
3990− Report.Report "PROBLEM IN RECORD" region [] $
3595+ Report.Report "UNFINISHED RECORD" region [] $
39913596 Code.toSnippet source surroundings (Just region)
39923597 (
39933598 D.reflow $
39943599 "I just started parsing a record, but I got stuck here:"
39953600 ,
3996− D.stack
3997− [ D.fillSep
3998− ["I","was","expecting","to","see","a","record","field","defined","next,"
3999− ,"so","I","am","looking","for","a","name","like"
4000− ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
4001− ]
4002− , D.toSimpleNote $
4003− "Field names must start with a lower-case letter. After that, you can use\
4004− \ any sequence of letters, numbers, and underscores."
4005− , noteForRecordError
3601+ D.fillSep
3602+ ["Records","look","like",D.dullyellow "{ x = 3, y = 4 },"
3603+ ,"so","I","was","expecting","to","see","a","field","name","next."
40063604 ]
40073605 )
40083606
@@ -4011,7 +3609,7 @@ toRecordReport source context record startRow startCol =
40113609 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
40123610 region = toRegion row col
40133611 in
4014− Report.Report "PROBLEM IN RECORD" region [] $
3612+ Report.Report "UNFINISHED RECORD" region [] $
40153613 Code.toSnippet source surroundings (Just region)
40163614 (
40173615 D.reflow $
@@ -4046,67 +3644,22 @@ toRecordReport source context record startRow startCol =
40463644 \ that is a reserved word. Try using a different name!"
40473645 )
40483646
4049− Code.Other (Just ',') ->
4050− let
4051− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4052− region = toRegion row col
4053− in
4054− Report.Report "EXTRA COMMA" region [] $
4055− Code.toSnippet source surroundings (Just region)
4056− (
4057− D.reflow $
4058− "I am partway through parsing a record, but I got stuck here:"
4059− ,
4060− D.stack
4061− [ D.reflow $
4062− "I am seeing two commas in a row. This is the second one!"
4063− , D.reflow $
4064− "Just delete one of the commas and you should be all set!"
4065− , noteForRecordError
4066− ]
4067− )
4068−
4069− Code.Close _ '}' ->
4070− let
4071− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4072− region = toRegion row col
4073− in
4074− Report.Report "EXTRA COMMA" region [] $
4075− Code.toSnippet source surroundings (Just region)
4076− (
4077− D.reflow $
4078− "I am partway through parsing a record, but I got stuck here:"
4079− ,
4080− D.stack
4081− [ D.reflow $
4082− "Trailing commas are not allowed in records. Try deleting the comma that appears\
4083− \ before this closing curly brace."
4084− , noteForRecordError
4085− ]
4086− )
4087−
40883647 _ ->
40893648 let
40903649 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
40913650 region = toRegion row col
40923651 in
4093− Report.Report "PROBLEM IN RECORD" region [] $
3652+ Report.Report "UNFINISHED RECORD" region [] $
40943653 Code.toSnippet source surroundings (Just region)
40953654 (
40963655 D.reflow $
4097− "I am partway through parsing a record, but I got stuck here:"
3656+ "I am partway through parsing a record, but I got stuck after that last comma:"
40983657 ,
4099− D.stack
4100− [ D.fillSep
4101− ["I","was","expecting","to","see","another","record","field","defined","next,"
4102− ,"so","I","am","looking","for","a","name","like"
4103− ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
4104− ]
4105− , D.toSimpleNote $
4106− "Field names must start with a lower-case letter. After that, you can use\
4107− \ any sequence of letters, numbers, and underscores."
4108− , noteForRecordError
4109− ]
3658+ addNoteForRecordError $
3659+ D.reflow $
3660+ "Trailing commas are not allowed in records, so I was expecting to see another\
3661+ \ record field defined next. If you are done defining the record, the fix may\
3662+ \ be to delete that last comma?"
41103663 )
41113664
41123665 RecordEquals row col ->
@@ -4114,19 +3667,17 @@ toRecordReport source context record startRow startCol =
41143667 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
41153668 region = toRegion row col
41163669 in
4117− Report.Report "PROBLEM IN RECORD" region [] $
3670+ Report.Report "UNFINISHED RECORD" region [] $
41183671 Code.toSnippet source surroundings (Just region)
41193672 (
41203673 D.reflow $
41213674 "I am partway through parsing a record, but I got stuck here:"
41223675 ,
4123− D.stack
4124− [ D.fillSep $
4125− ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
4126− ,"an","equals","sign","next.","So","try","putting","an",D.green "=","sign","here?"
4127− ]
4128− , noteForRecordError
4129− ]
3676+ addNoteForRecordError $
3677+ D.fillSep $
3678+ ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
3679+ ,"an","equals","sign","next.","So","try","putting","an",D.green "=","sign","here?"
3680+ ]
41303681 )
41313682
41323683 RecordExpr expr row col ->
@@ -4146,54 +3697,29 @@ toRecordReport source context record startRow startCol =
41463697 D.reflow $
41473698 "I just saw the opening curly brace of a record, but then I got stuck here:"
41483699 ,
4149− D.stack
4150− [ D.fillSep $
4151− ["I","am","expecting","a","record","like",D.dullyellow "{ x = 3, y = 4 }","here."
4152− ,"Try","defining","some","fields","of","your","own?"
4153− ]
4154− , noteForRecordIndentError
4155− ]
3700+ addNoteForRecordIndentError $
3701+ D.fillSep $
3702+ ["I","am","expecting","a","record","like",D.dullyellow "{ x = 3, y = 4 }","here."
3703+ ,"Try","defining","some","fields","of","your","own?"
3704+ ]
41563705 )
41573706
41583707 RecordIndentEnd row col ->
4159− case Code.nextLineStartsWithCloseCurly source row of
4160− Just (curlyRow, curlyCol) ->
4161− let
4162− surroundings = A.Region (A.Position startRow startCol) (A.Position curlyRow curlyCol)
4163− region = toRegion curlyRow curlyCol
4164− in
4165− Report.Report "NEED MORE INDENTATION" region [] $
4166− Code.toSnippet source surroundings (Just region)
4167− (
4168− D.reflow $
4169− "I was partway through parsing a record, but I got stuck here:"
4170− ,
4171− D.stack
4172− [ D.reflow $
4173− "I need this curly brace to be indented more. Try adding some spaces before it!"
4174− , noteForRecordError
4175− ]
4176− )
4177−
4178− Nothing ->
4179− let
4180− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4181− region = toRegion row col
4182− in
4183− Report.Report "UNFINISHED RECORD" region [] $
4184− Code.toSnippet source surroundings (Just region)
4185− (
4186− D.reflow $
4187− "I was partway through parsing a record, but I got stuck here:"
4188− ,
4189− D.stack
4190− [ D.fillSep $
4191− ["I","was","expecting","to","see","a","closing","curly","brace","next."
4192− ,"Try","putting","a",D.green "}","next","and","see","if","that","helps?"
4193− ]
4194− , noteForRecordIndentError
4195− ]
4196− )
3708+ let
3709+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3710+ region = toRegion row col
3711+ in
3712+ Report.Report "UNFINISHED RECORD" region [] $
3713+ Code.toSnippet source surroundings (Just region)
3714+ (
3715+ D.reflow $
3716+ "I was expecting to see a closing curly brace next:"
3717+ ,
3718+ addNoteForRecordIndentError $
3719+ D.fillSep $
3720+ ["Try","putting","an",D.green "}","and","see","if","that","helps?"
3721+ ]
3722+ )
41973723
41983724 RecordIndentField row col ->
41993725 let
@@ -4206,13 +3732,11 @@ toRecordReport source context record startRow startCol =
42063732 D.reflow $
42073733 "I am partway through parsing a record, but I got stuck after that last comma:"
42083734 ,
4209− D.stack
4210− [ D.reflow $
4211− "Trailing commas are not allowed in records, so the fix may be to\
4212− \ delete that last comma? Or maybe you were in the middle of defining\
4213− \ an additional field?"
4214− , noteForRecordError
4215− ]
3735+ addNoteForRecordError $
3736+ D.reflow $
3737+ "Trailing commas are not allowed in records, so the fix may be to\
3738+ \ delete that last comma? Or maybe you were in the middle of defining\
3739+ \ an additional field?"
42163740 )
42173741
42183742 RecordIndentEquals row col ->
@@ -4227,12 +3751,10 @@ toRecordReport source context record startRow startCol =
42273751 "I am partway through parsing a record. I just saw a record\
42283752 \ field, so I was expecting to see an equals sign next:"
42293753 ,
4230− D.stack
4231− [ D.fillSep $
4232− ["Try","putting","an",D.green "=","followed","by","an","expression?"
4233− ]
4234− , noteForRecordIndentError
4235− ]
3754+ addNoteForRecordIndentError $
3755+ D.fillSep $
3756+ ["Try","putting","an",D.green "=","followed","by","an","expression?"
3757+ ]
42363758 )
42373759
42383760 RecordIndentExpr row col ->
@@ -4246,48 +3768,52 @@ toRecordReport source context record startRow startCol =
42463768 D.reflow $
42473769 "I am partway through parsing a record, and I was expecting to run into an expression next:"
42483770 ,
4249− D.stack
4250− [ D.fillSep $
4251− ["Try","putting","something","like"
4252− ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
4253− ]
4254− , noteForRecordIndentError
4255− ]
3771+ addNoteForRecordIndentError $
3772+ D.fillSep $
3773+ ["Try","putting","something","like"
3774+ ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
3775+ ]
42563776 )
42573777
42583778
4259−noteForRecordError :: D.Doc
4260−noteForRecordError =
3779+addNoteForRecordError :: D.Doc -> D.Doc
3780+addNoteForRecordError normalRecommendation =
42613781 D.stack $
3782+ normalRecommendation
3783+ :
42623784 [ D.toSimpleNote
42633785 "If you are trying to define a record across multiple lines, I recommend using this format:"
42643786 , D.indent 4 $ D.vcat $
4265− [ "{ name = " <> D.dullyellow "\"Alice\""
4266− , ", age = " <> D.dullyellow "42"
4267− , ", height = " <> D.dullyellow "1.75"
3787+ [ "{ name = \"Alice\""
3788+ , ", age = 42"
3789+ , ", height = 1.75"
42683790 , "}"
42693791 ]
42703792 , D.reflow $
4271− "Notice that each line starts with some indentation. Usually two or four spaces.\
4272− \ This is the stylistic convention in the Elm ecosystem."
3793+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
3794+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
3795+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
42733796 ]
42743797
42753798
4276−noteForRecordIndentError :: D.Doc
4277−noteForRecordIndentError =
4278− D.stack
3799+addNoteForRecordIndentError :: D.Doc -> D.Doc
3800+addNoteForRecordIndentError normalRecommendation =
3801+ D.stack $
3802+ normalRecommendation
3803+ :
42793804 [ D.toSimpleNote
42803805 "I may be confused by indentation. For example, if you are trying to define\
42813806 \ a record across multiple lines, I recommend using this format:"
42823807 , D.indent 4 $ D.vcat $
4283− [ "{ name = " <> D.dullyellow "\"Alice\""
4284− , ", age = " <> D.dullyellow "42"
4285− , ", height = " <> D.dullyellow "1.75"
3808+ [ "{ name = \"Alice\""
3809+ , ", age = 42"
3810+ , ", height = 1.75"
42863811 , "}"
42873812 ]
42883813 , D.reflow $
4289− "Notice that each line starts with some indentation. Usually two or four spaces.\
4290− \ This is the stylistic convention in the Elm ecosystem!"
3814+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
3815+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
3816+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
42913817 ]
42923818
42933819
@@ -4476,14 +4002,15 @@ toListReport source context list startRow startCol =
44764002 , D.toSimpleNote
44774003 "I recommend using the following format for lists that span multiple lines:"
44784004 , D.indent 4 $ D.vcat $
4479− [ "[ " <> D.dullyellow "\"Alice\""
4480− , ", " <> D.dullyellow "\"Bob\""
4481− , ", " <> D.dullyellow "\"Chuck\""
4005+ [ "[ \"Alice\""
4006+ , ", \"Bob\""
4007+ , ", \"Chuck\""
44824008 , "]"
44834009 ]
44844010 , D.reflow $
4485− "Notice that each line starts with some indentation. Usually two or four spaces.\
4486− \ This is the stylistic convention in the Elm ecosystem."
4011+ "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4012+ \ This style can be jarring for people coming from C-like syntax, but folks generally\
4013+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
44874014 ]
44884015 )
44894016
@@ -4536,14 +4063,15 @@ toListReport source context list startRow startCol =
45364063 "I may be confused by indentation. For example, if you are trying to define\
45374064 \ a list across multiple lines, I recommend using this format:"
45384065 , D.indent 4 $ D.vcat $
4539− [ "[ " <> D.dullyellow "\"Alice\""
4540− , ", " <> D.dullyellow "\"Bob\""
4541− , ", " <> D.dullyellow "\"Chuck\""
4066+ [ "[ \"Alice\""
4067+ , ", \"Bob\""
4068+ , ", \"Chuck\""
45424069 , "]"
45434070 ]
45444071 , D.reflow $
4545− "Notice that each line starts with some indentation. Usually two or four spaces.\
4546− \ This is the stylistic convention in the Elm ecosystem."
4072+ "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4073+ \ This style can be jarring for people coming from C-like syntax, but folks generally\
4074+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
45474075 ]
45484076 )
45494077
@@ -4567,14 +4095,15 @@ toListReport source context list startRow startCol =
45674095 "I may be confused by indentation. For example, if you are trying to define\
45684096 \ a list across multiple lines, I recommend using this format:"
45694097 , D.indent 4 $ D.vcat $
4570− [ "[ " <> D.dullyellow "\"Alice\""
4571− , ", " <> D.dullyellow "\"Bob\""
4572− , ", " <> D.dullyellow "\"Chuck\""
4098+ [ "[ \"Alice\""
4099+ , ", \"Bob\""
4100+ , ", \"Chuck\""
45734101 , "]"
45744102 ]
45754103 , D.reflow $
4576− "Notice that each line starts with some indentation. Usually two or four spaces.\
4577− \ This is the stylistic convention in the Elm ecosystem."
4104+ "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4105+ \ This style can be jarring for people coming from C-like syntax, but folks generally\
4106+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
45784107 ]
45794108 )
45804109
@@ -4595,14 +4124,15 @@ toListReport source context list startRow startCol =
45954124 , D.toSimpleNote
45964125 "I recommend using the following format for lists that span multiple lines:"
45974126 , D.indent 4 $ D.vcat $
4598− [ "[ " <> D.dullyellow "\"Alice\""
4599− , ", " <> D.dullyellow "\"Bob\""
4600− , ", " <> D.dullyellow "\"Chuck\""
4127+ [ "[ \"Alice\""
4128+ , ", \"Bob\""
4129+ , ", \"Chuck\""
46014130 , "]"
46024131 ]
46034132 , D.reflow $
4604− "Notice that each line starts with some indentation. Usually two or four spaces.\
4605− \ This is the stylistic convention in the Elm ecosystem."
4133+ "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4134+ \ This style can be jarring for people coming from C-like syntax, but folks generally\
4135+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
46064136 ]
46074137 )
46084138
@@ -4851,7 +4381,7 @@ toPatternReport source context pattern startRow startCol =
48514381 ,"((" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> ") " <> D.cyan "as" <> D.dullyellow " point" <> ")"
48524382 ,"so","you","can","refer","to","individual","parts","of","the","tuple","with"
48534383 ,D.dullyellow "x","and",D.dullyellow "y","or","you","refer","to","the","whole"
4854− ,"thing","with",D.dullyellow "point" <> "."
4384+ ,"thing","with",D.dullyellow "point."
48554385 ]
48564386 , D.reflow $
48574387 "So I was expecting to see a variable name after the `as` keyword here. Sometimes\
@@ -5043,7 +4573,7 @@ toPTupleReport source context tuple startRow startCol =
50434573 "I just saw an open parenthesis, but I got stuck here:"
50444574 ,
50454575 D.fillSep
5046− ["I","was","expecting","to","see","a","pattern","next."
4576+ ["I","was","expecting","so","see","a","pattern","next."
50474577 ,"Maybe","it","will","end","up","being","something"
50484578 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "?"
50494579 ]
@@ -5152,7 +4682,7 @@ toPTupleReport source context tuple startRow startCol =
51524682 "I just saw an open parenthesis, but then I got stuck here:"
51534683 ,
51544684 D.fillSep
5155− ["I","was","expecting","to","see","a","pattern","next."
4685+ ["I","was","expecting","so","see","a","pattern","next."
51564686 ,"Maybe","it","will","end","up","being","something"
51574687 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "?"
51584688 ]
@@ -5171,7 +4701,7 @@ toPTupleReport source context tuple startRow startCol =
51714701 ,
51724702 D.stack
51734703 [ D.fillSep
5174− ["I","was","expecting","to","see","a","pattern","next."
4704+ ["I","was","expecting","so","see","a","pattern","next."
51754705 ,"I","am","expecting","the","final","result","to","be","something"
51764706 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "."
51774707 ]
@@ -5475,64 +5005,22 @@ toTRecordReport source context record startRow startCol =
54755005 \ that is a reserved word. Try using a different name!"
54765006 )
54775007
5478− Code.Other (Just ',') ->
5479− let
5480− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5481− region = toRegion row col
5482− in
5483− Report.Report "EXTRA COMMA" region [] $
5484− Code.toSnippet source surroundings (Just region)
5485− (
5486− D.reflow $
5487− "I am partway through parsing a record type, but I got stuck here:"
5488− ,
5489− D.stack
5490− [ D.reflow $
5491− "I am seeing two commas in a row. This is the second one!"
5492− , D.reflow $
5493− "Just delete one of the commas and you should be all set!"
5494− , noteForRecordTypeError
5495− ]
5496− )
5497−
5498− Code.Close _ '}' ->
5499− let
5500− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5501− region = toRegion row col
5502− in
5503− Report.Report "EXTRA COMMA" region [] $
5504− Code.toSnippet source surroundings (Just region)
5505− (
5506− D.reflow $
5507− "I am partway through parsing a record type, but I got stuck here:"
5508− ,
5509− D.stack
5510− [ D.reflow $
5511− "Trailing commas are not allowed in record types. Try deleting the comma that\
5512− \ appears before this closing curly brace."
5513− , noteForRecordTypeError
5514− ]
5515− )
5516−
55175008 _ ->
55185009 let
55195010 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
55205011 region = toRegion row col
55215012 in
5522− Report.Report "PROBLEM IN RECORD TYPE" region [] $
5013+ Report.Report "UNFINISHED RECORD TYPE" region [] $
55235014 Code.toSnippet source surroundings (Just region)
55245015 (
55255016 D.reflow $
5526− "I am partway through parsing a record type, but I got stuck here:"
5017+ "I am partway through parsing a record type, but I got stuck after that last comma:"
55275018 ,
5528− D.stack
5529− [ D.fillSep
5530− ["I","was","expecting","to","see","another","record","field","defined","next,"
5531− ,"so","I","am","looking","for","a","name","like"
5532− ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
5533− ]
5534− , noteForRecordTypeError
5535− ]
5019+ addNoteForRecordTypeError $
5020+ D.reflow $
5021+ "Trailing commas are not allowed in records, so I was expecting to see another\
5022+ \ record field defined next. If you are done defining the record, the fix may\
5023+ \ be to delete that last comma?"
55365024 )
55375025
55385026 TRecordColon row col ->
@@ -5546,13 +5034,11 @@ toTRecordReport source context record startRow startCol =
55465034 D.reflow $
55475035 "I am partway through parsing a record type, but I got stuck here:"
55485036 ,
5549− D.stack
5550− [ D.fillSep $
5551− ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
5552− ,"a","colon","next.","So","try","putting","an",D.green ":","sign","here?"
5553− ]
5554− , noteForRecordTypeError
5555− ]
5037+ addNoteForRecordTypeError $
5038+ D.fillSep $
5039+ ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
5040+ ,"a","colon","next.","So","try","putting","an",D.green ":","sign","here?"
5041+ ]
55565042 )
55575043
55585044 TRecordType tipe row col ->
@@ -5572,54 +5058,29 @@ toTRecordReport source context record startRow startCol =
55725058 D.reflow $
55735059 "I just saw the opening curly brace of a record type, but then I got stuck here:"
55745060 ,
5575− D.stack
5576− [ D.fillSep $
5577− ["I","am","expecting","a","record","like",D.dullyellow "{ name : String, age : Int }","here."
5578− ,"Try","defining","some","fields","of","your","own?"
5579− ]
5580− , noteForRecordTypeIndentError
5581− ]
5061+ addNoteForRecordTypeIndentError $
5062+ D.fillSep $
5063+ ["I","am","expecting","a","record","like",D.dullyellow "{ name : String, age : Int }","here."
5064+ ,"Try","defining","some","fields","of","your","own?"
5065+ ]
55825066 )
55835067
55845068 TRecordIndentEnd row col ->
5585− case Code.nextLineStartsWithCloseCurly source row of
5586− Just (curlyRow, curlyCol) ->
5587− let
5588− surroundings = A.Region (A.Position startRow startCol) (A.Position curlyRow curlyCol)
5589− region = toRegion curlyRow curlyCol
5590− in
5591− Report.Report "NEED MORE INDENTATION" region [] $
5592− Code.toSnippet source surroundings (Just region)
5593− (
5594− D.reflow $
5595− "I was partway through parsing a record type, but I got stuck here:"
5596− ,
5597− D.stack
5598− [ D.reflow $
5599− "I need this curly brace to be indented more. Try adding some spaces before it!"
5600− , noteForRecordTypeError
5601− ]
5602− )
5603−
5604− Nothing ->
5605− let
5606− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5607− region = toRegion row col
5608− in
5609− Report.Report "UNFINISHED RECORD TYPE" region [] $
5610− Code.toSnippet source surroundings (Just region)
5611− (
5612− D.reflow $
5613− "I was partway through parsing a record type, but I got stuck here:"
5614− ,
5615− D.stack
5616− [ D.fillSep $
5617− ["I","was","expecting","to","see","a","closing","curly","brace","next."
5618− ,"Try","putting","a",D.green "}","next","and","see","if","that","helps?"
5619− ]
5620− , noteForRecordTypeIndentError
5621− ]
5622− )
5069+ let
5070+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5071+ region = toRegion row col
5072+ in
5073+ Report.Report "UNFINISHED RECORD TYPE" region [] $
5074+ Code.toSnippet source surroundings (Just region)
5075+ (
5076+ D.reflow $
5077+ "I was expecting to see a closing curly brace next:"
5078+ ,
5079+ addNoteForRecordTypeIndentError $
5080+ D.fillSep $
5081+ ["Try","putting","an",D.green "}","and","see","if","that","helps?"
5082+ ]
5083+ )
56235084
56245085 TRecordIndentField row col ->
56255086 let
@@ -5632,13 +5093,11 @@ toTRecordReport source context record startRow startCol =
56325093 D.reflow $
56335094 "I am partway through parsing a record type, but I got stuck after that last comma:"
56345095 ,
5635− D.stack
5636− [ D.reflow $
5637− "Trailing commas are not allowed in record types, so the fix may be to\
5638− \ delete that last comma? Or maybe you were in the middle of defining\
5639− \ an additional field?"
5640− , noteForRecordTypeIndentError
5641− ]
5096+ addNoteForRecordTypeIndentError $
5097+ D.reflow $
5098+ "Trailing commas are not allowed in record types, so the fix may be to\
5099+ \ delete that last comma? Or maybe you were in the middle of defining\
5100+ \ an additional field?"
56425101 )
56435102
56445103 TRecordIndentColon row col ->
@@ -5653,12 +5112,10 @@ toTRecordReport source context record startRow startCol =
56535112 "I am partway through parsing a record type. I just saw a record\
56545113 \ field, so I was expecting to see a colon next:"
56555114 ,
5656− D.stack
5657− [ D.fillSep $
5658− ["Try","putting","an",D.green ":","followed","by","a","type?"
5659− ]
5660− , noteForRecordTypeIndentError
5661− ]
5115+ addNoteForRecordTypeIndentError $
5116+ D.fillSep $
5117+ ["Try","putting","an",D.green ":","followed","by","a","type?"
5118+ ]
56625119 )
56635120
56645121 TRecordIndentType row col ->
@@ -5672,19 +5129,19 @@ toTRecordReport source context record startRow startCol =
56725129 D.reflow $
56735130 "I am partway through parsing a record type, and I was expecting to run into a type next:"
56745131 ,
5675− D.stack
5676− [ D.fillSep $
5677− ["Try","putting","something","like"
5678− ,D.dullyellow "Int","or",D.dullyellow "String","for","now?"
5679− ]
5680− , noteForRecordTypeIndentError
5681− ]
5132+ addNoteForRecordTypeIndentError $
5133+ D.fillSep $
5134+ ["Try","putting","something","like"
5135+ ,D.dullyellow "Int","or",D.dullyellow "String","for","now?"
5136+ ]
56825137 )
56835138
56845139
5685−noteForRecordTypeError :: D.Doc
5686−noteForRecordTypeError =
5140+addNoteForRecordTypeError :: D.Doc -> D.Doc
5141+addNoteForRecordTypeError normalRecommendation =
56875142 D.stack $
5143+ normalRecommendation
5144+ :
56885145 [ D.toSimpleNote
56895146 "If you are trying to define a record type across multiple lines, I recommend using this format:"
56905147 , D.indent 4 $ D.vcat $
@@ -5694,14 +5151,17 @@ noteForRecordTypeError =
56945151 , "}"
56955152 ]
56965153 , D.reflow $
5697− "Notice that each line starts with some indentation. Usually two or four spaces.\
5698− \ This is the stylistic convention in the Elm ecosystem."
5154+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
5155+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5156+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
56995157 ]
57005158
57015159
5702−noteForRecordTypeIndentError :: D.Doc
5703−noteForRecordTypeIndentError =
5160+addNoteForRecordTypeIndentError :: D.Doc -> D.Doc
5161+addNoteForRecordTypeIndentError normalRecommendation =
57045162 D.stack $
5163+ normalRecommendation
5164+ :
57055165 [ D.toSimpleNote
57065166 "I may be confused by indentation. For example, if you are trying to define\
57075167 \ a record type across multiple lines, I recommend using this format:"
@@ -5712,8 +5172,9 @@ noteForRecordTypeIndentError =
57125172 , "}"
57135173 ]
57145174 , D.reflow $
5715− "Notice that each line starts with some indentation. Usually two or four spaces.\
5716− \ This is the stylistic convention in the Elm ecosystem."
5175+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
5176+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5177+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
57175178 ]
57185179
57195180
@@ -5765,7 +5226,7 @@ toTTupleReport source context tuple startRow startCol =
57655226 Code.toSnippet source surroundings (Just region)
57665227 (
57675228 D.reflow $
5768− "I was expecting to see a closing parenthesis next, but I got stuck here:"
5229+ "I was expecting to see a closing parentheses next, but I got stuck here:"
57695230 ,
57705231 D.stack
57715232 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]