@@ -69,6 +69,9 @@ 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
7275 | ParseError Module
7376
7477
@@ -561,10 +564,84 @@ toReport source err =
561564 ]
562565 )
563566
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+
564619 ParseError modul ->
565620 toParseErrorReport source modul
566621
567622
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+
568645toParseErrorReport :: Code.Source -> Module -> Report.Report
569646toParseErrorReport source modul =
570647 case modul of
@@ -572,156 +649,9 @@ toParseErrorReport source modul =
572649 toSpaceReport source space row col
573650
574651 ModuleBadEnd 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 maybeChar ->
620− let
621− region = toRegion row col
622− in
623− case maybeChar of
624− Just ';' ->
625− Report.Report "UNEXPECTED SEMICOLON" region [] $
626− Code.toSnippet source region Nothing
627− (
628− D.reflow $
629− "I got stuck on this semicolon:"
630− ,
631− D.stack
632− [ D.reflow $ "Try removing it?"
633− , D.toSimpleNote $
634− "Some languages require semicolons at the end of each statement. These are\
635− \ often called C-like languages, and they usually share a lot of language design\
636− \ choices. (E.g. side-effects, for loops, etc.) Elm manages effects with commands\
637− \ and subscriptions instead, so there is no special syntax for \"statements\" and\
638− \ therefore no need to use semicolons to separate them. I think this will make\
639− \ more sense as you work through https://guide.elm-lang.org though!"
640− ]
641− )
642−
643− Just ',' ->
644− Report.Report "UNEXPECTED COMMA" region [] $
645− Code.toSnippet source region Nothing
646− (
647− D.reflow $
648− "I got stuck on this comma:"
649− ,
650− D.stack
651− [ D.reflow $
652− "I do not think I am parsing a list or tuple right now. Try deleting the comma?"
653− , D.toSimpleNote $
654− "If this is supposed to be part of a list, the problem may be a bit earlier.\
655− \ Perhaps the opening [ is missing? Or perhaps some value in the list has an extra\
656− \ closing ] that is making me think the list ended earlier? The same kinds of\
657− \ things could be going wrong if this is supposed to be a tuple."
658− ]
659− )
660−
661− Just '`' ->
662− Report.Report "UNEXPECTED CHARACTER" region [] $
663− Code.toSnippet source region Nothing
664− (
665− D.reflow $
666− "I got stuck on this character:"
667− ,
668− D.stack
669− [ D.reflow $
670− "It is not used for anything in Elm syntax. It is used for multi-line strings in\
671− \ some languages though, so if you want a string that spans multiple lines, you\
672− \ can use Elm's multi-line string syntax like this:"
673− , D.vcat
674− [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
675− , mempty
676− , D.dullyellow "# Multi-line Strings"
677− , mempty
678− , D.dullyellow "- start with triple double quotes"
679− , D.dullyellow "- write whatever you want"
680− , D.dullyellow "- no need to escape newlines or double quotes"
681− , D.dullyellow "- end with triple double quotes"
682− , mempty
683− , D.dullyellow "\"\"\""
684− ]
685− , D.reflow $
686− "Otherwise I do not know what is going on! Try removing the character?"
687− ]
688− )
689−
690− Just '$' ->
691− Report.Report "UNEXPECTED SYMBOL" region [] $
692− Code.toSnippet source region Nothing
693− (
694− D.reflow $
695− "I got stuck on this dollar sign:"
696− ,
697− D.reflow $
698− "It is not used for anything in Elm syntax. Are you coming from a language where\
699− \ dollar signs can be used in variable names? If so, try a name that (1) starts\
700− \ with a letter and (2) only contains letters, numbers, and underscores."
701− )
702−
703− Just c | elem c ['#','@','!','%','~'] ->
704− Report.Report "UNEXPECTED SYMBOL" region [] $
705− Code.toSnippet source region Nothing
706− (
707− D.reflow $
708− "I got stuck on this symbol:"
709− ,
710− D.reflow $
711− "It is not used for anything in Elm syntax. Try removing it?"
712− )
713−
714− _ ->
715− Report.Report "SYNTAX PROBLEM" region [] $
716− Code.toSnippet source region Nothing
717− (
718− D.reflow $
719− "I got stuck here:"
720− ,
721− D.reflow $
722− "Whatever I am running into is confusing me a lot! Normally I can give fairly\
723− \ specific hints, but something is really tripping me up this time."
724− )
652+ if col == 1
653+ then toDeclStartReport source row col
654+ else toWeirdEndReport source row col
725655
726656 ModuleProblem row col ->
727657 let
@@ -867,15 +797,15 @@ toParseErrorReport source modul =
867797 [ D.reflow $
868798 "I am not sure what is going on, but I recommend starting an Elm\
869799 \ file with the following lines:"
870− , D.vcat
800+ , D.indent 4 $ D.vcat $
871801 [ D.fillSep [D.cyan "import","Html"]
872802 , ""
873− , D.fillSep [D.green "main","="]
874− , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
803+ , "main ="
804+ , " Html.text " <> D.dullyellow "\"Hello!\""
875805 ]
876806 , D.reflow $
877− "You should be able to copy those lines directly into your file. Check out\
878− \ some of the examples on https://elm-lang.org for more help getting started!"
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!"
879809 , D.toSimpleNote $
880810 "This can also happen when something is indented too much!"
881811 ]
@@ -900,11 +830,12 @@ toParseErrorReport source modul =
900830 , D.indent 4 $ D.vcat $
901831 [ D.fillSep [D.cyan "import","Dict"]
902832 , D.fillSep [D.cyan "import","Maybe"]
903− , D.fillSep [D.cyan "import","Html.Attributes"]
904− , D.fillSep [D.cyan "import","Json.Decode"]
833+ , D.fillSep [D.cyan "import","Html.Attributes",D.cyan "as","A"]
834+ , D.fillSep [D.cyan "import","Json.Decode",D.cyan "exposing","(..)"]
905835 ]
906836 , D.reflow $
907837 "Notice that the module names all start with capital letters. That is required!"
838+ , D.reflowLink "Read" "imports" "to learn more."
908839 ]
909840 )
910841
@@ -931,6 +862,7 @@ toParseErrorReport source modul =
931862 ]
932863 , D.reflow $
933864 "Notice that the alias always starts with a capital letter. That is required!"
865+ , D.reflowLink "Read" "imports" "to learn more."
934866 ]
935867 )
936868
@@ -993,6 +925,192 @@ toParseErrorReport source modul =
993925
994926
995927
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+
9961114-- IMPORTS
9971115
9981116
@@ -1018,6 +1136,7 @@ toImportReport source row col =
10181136 ]
10191137 , D.reflow $
10201138 "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."
10211140 ]
10221141 )
10231142
@@ -1324,106 +1443,7 @@ toDeclarationsReport :: Code.Source -> Decl -> Report.Report
13241443toDeclarationsReport source decl =
13251444 case decl of
13261445 DeclStart row col ->
1327− case Code.whatIsNext source row col of
1328− Code.Close term bracket ->
1329− let
1330− region = toRegion row col
1331− in
1332− Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
1333− Code.toSnippet source region Nothing
1334− (
1335− D.reflow $
1336− "I was not expecting to see a " ++ term ++ " here:"
1337− , D.reflow $
1338− "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
1339− )
1340−
1341− Code.Keyword keyword ->
1342− let
1343− region = toKeywordRegion row col keyword
1344− in
1345− Report.Report "RESERVED WORD" region [] $
1346− Code.toSnippet source region Nothing
1347− (
1348− D.reflow $
1349− "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
1350− ,
1351− case keyword of
1352− "import" ->
1353− D.reflow $
1354− "It is reserved for declaring imports at the top of your module. If you want\
1355− \ another import, try moving it up top with the other imports. If you want to\
1356− \ define a value or function, try changing the name to something else!"
1357−
1358− "case" ->
1359− D.stack
1360− [ D.reflow $
1361− "It is reserved for writing `case` expressions. Try using a different name?"
1362− , D.toSimpleNote $
1363− "If you are trying to write a `case` expression, it needs to be part of a\
1364− \ definition. So you could write something like this instead:"
1365− , D.vcat $
1366− [ D.indent 0 $ D.fillSep [D.green "getWidth","maybeWidth","="]
1367− , D.indent 2 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
1368− , D.indent 4 $ D.fillSep [D.blue "Just","width","->"]
1369− , D.indent 6 $ D.fillSep ["width","+",D.dullyellow "200"]
1370− , ""
1371− , D.indent 4 $ D.fillSep [D.blue "Nothing","->"]
1372− , D.indent 6 $ D.fillSep [D.dullyellow "400"]
1373− ]
1374− , D.reflow $
1375− "This defines a `getWidth` function that we can use elsewhere in our program."
1376− ]
1377−
1378− "if" ->
1379− D.stack
1380− [ D.reflow $
1381− "It is reserved for writing `if` expressions. Try using a different name?"
1382− , D.toSimpleNote $
1383− "If you are trying to write an `if` expression, it needs to be part of a\
1384− \ definition. So you could write something like this instead:"
1385− , D.vcat $
1386− [ D.indent 0 $ D.fillSep [D.green "reviewPowerLevel","powerLevel","="]
1387− , D.indent 2 $ D.fillSep $
1388− [D.cyan "if","powerLevel",">",D.dullyellow "9000"
1389− ,D.cyan "then",D.dullyellow "\"OVER 9000!!!\""
1390− ,D.cyan "else",D.dullyellow "\"not bad\""
1391− ]
1392− ]
1393− , D.reflow $
1394− "This defines a `reviewPowerLevel` function that we can use elsewhere in our program."
1395− ]
1396−
1397− _ ->
1398− D.reflow $
1399− "It is a reserved word. Try changing the name to something else?"
1400− )
1401−
1402− _ ->
1403− let
1404− region = toRegion row col
1405− in
1406− Report.Report "SYNTAX PROBLEM" region [] $
1407− Code.toSnippet source region Nothing
1408− (
1409− D.reflow $
1410− "I was expecting to see a new declaration here:"
1411− ,
1412− D.stack
1413− [ D.reflow $
1414− "I am not sure what is going wrong exactly, but here are a couple valid\
1415− \ declarations for reference:"
1416− , D.vcat
1417− [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
1418− , D.fillSep [D.green "add","x","y","="]
1419− , D.fillSep [" ","x","+","y"]
1420− ]
1421− , D.fillSep [D.cyan "type",D.green "User","=","Anonymous","|","LoggedIn String"]
1422− , D.reflow $
1423− "Note that all declarations start with lower-case letters in Elm. Capitalization\
1424− \ makes a difference, so be conscious of that if you are working from examples!"
1425− ]
1426− )
1446+ toDeclStartReport source row col
14271447
14281448 DeclSpace space row col ->
14291449 toSpaceReport source space row col
@@ -1453,6 +1473,165 @@ toDeclarationsReport source decl =
14531473 )
14541474
14551475
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+
14561635
14571636-- PORT
14581637
@@ -1579,7 +1758,7 @@ toPortReport source port_ startRow startCol =
15791758 [ D.reflow $
15801759 "I was expecting to see a type next. Here are examples of outgoing and\
15811760 \ incoming ports for reference:"
1582− , D.vcat
1761+ , D.indent 4 $ D.vcat $
15831762 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
15841763 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
15851764 ]
@@ -1598,7 +1777,7 @@ portNote =
15981777 D.stack
15991778 [ D.toSimpleNote $
16001779 "Here are some example `port` declarations for reference:"
1601− , D.vcat
1780+ , D.indent 4 $ D.vcat $
16021781 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
16031782 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
16041783 ]
@@ -1781,8 +1960,8 @@ typeAliasNote =
17811960 [ D.toSimpleNote $
17821961 "Here is an example of a valid `type alias` for reference:"
17831962 , D.vcat $
1784− [ D.indent 0 $ D.fillSep [D.cyan "type",D.cyan "alias",D.green "Person","="]
1785− , D.indent 2 $ D.vcat $
1963+ [ D.indent 4 $ D.fillSep [D.cyan "type",D.cyan "alias","Person","="]
1964+ , D.indent 6 $ D.vcat $
17861965 ["{ name : String"
17871966 ,", age : Int"
17881967 ,", height : Float"
@@ -1982,10 +2161,10 @@ customTypeNote =
19822161 [ D.toSimpleNote $
19832162 "Here is an example of a valid `type` declaration for reference:"
19842163 , D.vcat $
1985− [ D.indent 0 $ D.fillSep [D.cyan "type",D.green "Status"]
1986− , D.indent 2 $ D.fillSep ["=","Failure"]
1987− , D.indent 2 $ D.fillSep ["|","Waiting"]
1988− , D.indent 2 $ D.fillSep ["|","Success","String"]
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"]
19892168 ]
19902169 , D.reflow $
19912170 "This defines a new `Status` type with three variants. This could be useful if\
@@ -2016,11 +2195,55 @@ toDeclDefReport source name declDef startRow startCol =
20162195 Report.Report "RESERVED WORD" region [] $
20172196 Code.toSnippet source surroundings (Just region)
20182197 (
2019− D.reflow $
2020− "It looks like you are trying to use `" ++ keyword ++ "` as an argument:"
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+ ]
20212204 ,
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 [] $
2228+ Code.toSnippet source surroundings (Just region)
2229+ (
20222230 D.reflow $
2023− "This is a reserved word! Try using some other name?"
2231+ "I was not expecting to see an arrow here:"
2232+ ,
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+ ]
20242247 )
20252248
20262249 Code.Operator op ->
@@ -2038,10 +2261,10 @@ toDeclDefReport source name declDef startRow startCol =
20382261 [ D.reflow $
20392262 "I am not sure what is going wrong exactly, so here is a valid\
20402263 \ definition (with an optional type annotation) for reference:"
2041− , D.vcat
2042− [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2043− , D.fillSep [D.green "add","x","y","="]
2044− , D.fillSep [" ","x","+","y"]
2264+ , D.indent 4 $ D.vcat $
2265+ [ "greet : String -> String"
2266+ , "greet name ="
2267+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
20452268 ]
20462269 , D.reflow $
20472270 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -2063,10 +2286,10 @@ toDeclDefReport source name declDef startRow startCol =
20632286 [ D.reflow $
20642287 "I am not sure what is going wrong exactly, so here is a valid\
20652288 \ definition (with an optional type annotation) for reference:"
2066− , D.vcat
2067− [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2068− , D.fillSep [D.green "add","x","y","="]
2069− , D.fillSep [" ","x","+","y"]
2289+ , D.indent 4 $ D.vcat $
2290+ [ "greet : String -> String"
2291+ , "greet name ="
2292+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
20702293 ]
20712294 , D.reflow $
20722295 "Try to use that format!"
@@ -2181,10 +2404,10 @@ declDefNote =
21812404 D.stack
21822405 [ D.reflow $
21832406 "Here is a valid definition (with a type annotation) for reference:"
2184− , D.vcat
2185− [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2186− , D.fillSep [D.green "add","x","y","="]
2187− , D.fillSep [" ","x","+","y"]
2407+ , D.indent 4 $ D.vcat $
2408+ [ "greet : String -> String"
2409+ , "greet name ="
2410+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
21882411 ]
21892412 , D.reflow $
21902413 "The top line (called a \"type annotation\") is optional. You can leave it off\
@@ -2296,25 +2519,40 @@ toExprReport source context expr startRow startCol =
22962519 )
22972520
22982521 OperatorRight op row col ->
2299− let region = toRegion row col in
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
23002527 Report.Report "MISSING EXPRESSION" region [] $
2301− Code.toSnippet source region Nothing
2528+ Code.toSnippet source surroundings (Just region)
23022529 (
23032530 D.reflow $
2304− "I was expecting to see an expression after this " ++ Name.toChars op ++ " operator:"
2531+ "I just saw a " ++ Name.toChars op ++ " "
2532+ ++ (if isMath then "sign" else "operator")
2533+ ++ ", so I am getting stuck here:"
23052534 ,
2306− D.stack
2307− [ D.fillSep $
2308− ["You","can","just","put","anything","for","now,","like"
2309− ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
2310− ,"Once","there","is","something","there,","I","can","probably"
2311− ,"give","a","more","specific","hint!"
2312− ]
2313− , D.toSimpleNote $
2314− "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
2315− \ Or if I run into operators in unexpected spots. Point is, there are a\
2316− \ couple ways I can get confused and give sort of weird advice!"
2317− ]
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."
23182556 )
23192557
23202558 OperatorReserved operator row col ->
@@ -2353,7 +2591,7 @@ toExprReport source context expr startRow startCol =
23532591 ,"give","a","more","specific","hint!"
23542592 ]
23552593 , D.toSimpleNote $
2356− "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
2594+ "This can also happen if I run into reserved words like `let` or `as` unexpectedly.\
23572595 \ Or if I run into operators in unexpected spots. Point is, there are a\
23582596 \ couple ways I can get confused and give sort of weird advice!"
23592597 ]
@@ -2502,17 +2740,15 @@ toStringReport source string row col =
25022740 , D.toSimpleNote $
25032741 "For a string that spans multiple lines, you can use the multi-line string\
25042742 \ syntax like this:"
2505− , D.vcat
2506− [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
2507− , mempty
2508− , D.dullyellow "# Multi-line Strings"
2509− , mempty
2510− , D.dullyellow "- start with triple double quotes"
2511− , D.dullyellow "- write whatever you want"
2512− , D.dullyellow "- no need to escape newlines or double quotes"
2513− , D.dullyellow "- end with triple double quotes"
2514− , mempty
2515− , D.dullyellow "\"\"\""
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+ , "\"\"\""
25162752 ]
25172753 ]
25182754 )
@@ -2531,17 +2767,15 @@ toStringReport source string row col =
25312767 [ D.reflow "Add a \"\"\" somewhere after this to end the string."
25322768 , D.toSimpleNote $
25332769 "Here is a valid multi-line string for reference:"
2534− , D.vcat
2535− [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
2536− , mempty
2537− , D.dullyellow "# Multi-line Strings"
2538− , mempty
2539− , D.dullyellow "- start with triple double quotes"
2540− , D.dullyellow "- write whatever you want"
2541− , D.dullyellow "- no need to escape newlines or double quotes"
2542− , D.dullyellow "- end with triple double quotes"
2543− , mempty
2544− , D.dullyellow "\"\"\""
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+ , "\"\"\""
25452779 ]
25462780 ]
25472781 )
@@ -2793,7 +3027,7 @@ toOperatorReport source context operator row col =
27933027 ,
27943028 D.stack
27953029 [ D.reflow $
2796− "It makes sense to see arrows around here, so I suspect it is something earlier."
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?"
27973031 , noteForCaseIndentError
27983032 ]
27993033 )
@@ -2801,11 +3035,15 @@ toOperatorReport source context operator row col =
28013035 else
28023036 (
28033037 D.reflow $
2804− "I was not expecting an arrow here:"
3038+ "I was partway through parsing an expression when I got stuck on this arrow:"
28053039 ,
2806− D.reflow $
2807− "Arrows should only appear in `case` expressions and anonymous functions. Maybe\
2808− \ you want > or >= instead?"
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+ ]
28093047 )
28103048
28113049 BadEquals ->
@@ -3002,8 +3240,8 @@ toUnfinishLetReport source row col startRow startCol message =
30023240 [ message
30033241 , D.toSimpleNote $
30043242 "Here is an example with a valid `let` expression for reference:"
3005− , D.vcat $
3006− [ D.indent 0 $ D.fillSep [D.green "viewPerson","person","="]
3243+ , D.indent 4 $ D.vcat $
3244+ [ D.indent 0 $ D.fillSep ["viewPerson","person","="]
30073245 , D.indent 2 $ D.fillSep [D.cyan "let"]
30083246 , D.indent 4 $ D.fillSep ["fullName","="]
30093247 , D.indent 6 $ D.fillSep ["person.firstName","++",D.dullyellow "\" \"","++","person.lastName"]
@@ -3075,16 +3313,60 @@ toLetDefReport source name def startRow startCol =
30753313 Code.Keyword keyword ->
30763314 let
30773315 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3078− region = toKeywordRegion row col keyword
3316+ region = toKeywordRegion row col keyword
3317+ in
3318+ 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
30793349 in
3080− Report.Report "RESERVED WORD" region [] $
3350+ Report.Report "MISSING COLON?" region [] $
30813351 Code.toSnippet source surroundings (Just region)
30823352 (
30833353 D.reflow $
3084− "It looks like you are trying to use `" ++ keyword ++ "` as an argument:"
3354+ "I was not expecting to see an arrow here:"
30853355 ,
3086− D.reflow $
3087− "This is a reserved word! Try using some other name?"
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+ ]
30883370 )
30893371
30903372 Code.Operator op ->
@@ -3102,10 +3384,10 @@ toLetDefReport source name def startRow startCol =
31023384 [ D.reflow $
31033385 "I am not sure what is going wrong exactly, so here is a valid\
31043386 \ definition (with an optional type annotation) for reference:"
3105− , D.vcat
3106− [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3107− , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3108− , D.indent 6 $ D.fillSep ["x","+","y"]
3387+ , D.indent 4 $ D.vcat $
3388+ [ "greet : String -> String"
3389+ , "greet name ="
3390+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
31093391 ]
31103392 , D.reflow $
31113393 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -3127,10 +3409,10 @@ toLetDefReport source name def startRow startCol =
31273409 [ D.reflow $
31283410 "I am not sure what is going wrong exactly, so here is a valid\
31293411 \ definition (with an optional type annotation) for reference:"
3130− , D.vcat
3131− [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3132− , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3133− , D.indent 4 $ D.fillSep ["x","+","y"]
3412+ , D.indent 4 $ D.vcat $
3413+ [ "greet : String -> String"
3414+ , "greet name ="
3415+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
31343416 ]
31353417 , D.reflow $
31363418 "Try to use that format!"
@@ -3220,10 +3502,10 @@ defNote =
32203502 D.stack
32213503 [ D.reflow $
32223504 "Here is a valid definition (with a type annotation) for reference:"
3223− , D.vcat
3224− [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3225− , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3226− , D.indent 6 $ D.fillSep ["x","+","y"]
3505+ , D.indent 4 $ D.vcat $
3506+ [ "greet : String -> String"
3507+ , "greet name ="
3508+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
32273509 ]
32283510 , D.reflow $
32293511 "The top line (called a \"type annotation\") is optional. You can leave it off\
@@ -3482,8 +3764,9 @@ noteForCaseIndentError =
34823764 , D.indent 8 $ D.fillSep [D.dullyellow "400"]
34833765 ]
34843766 , D.reflow $
3485− "Notice the indentation! Each pattern is aligned, and each branch is indented\
3486− \ a bit more than the corresponding pattern. That is important!"
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!"
34873770 ]
34883771
34893772
@@ -3635,23 +3918,43 @@ toIfReport source context if_ startRow startCol =
36353918 )
36363919
36373920 IfIndentElse row col ->
3638− let
3639− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3640− region = toRegion row col
3641− in
3642− Report.Report "UNFINISHED IF" region [] $
3643− Code.toSnippet source surroundings (Just region)
3644− (
3645− D.reflow $
3646− "I was expecting to see an `else` branch after this:"
3647− ,
3648− D.stack
3649− [ D.reflow $
3650− "I know what to do when the condition is `True`, but not when it is `False`."
3651− , D.fillSep
3652− ["Add","an",D.cyan "else","branch","to","handle","that","scenario!"]
3653− ]
3654− )
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+ )
36553958
36563959
36573960
@@ -3684,15 +3987,22 @@ toRecordReport source context record startRow startCol =
36843987 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
36853988 region = toRegion row col
36863989 in
3687− Report.Report "UNFINISHED RECORD" region [] $
3990+ Report.Report "PROBLEM IN RECORD" region [] $
36883991 Code.toSnippet source surroundings (Just region)
36893992 (
36903993 D.reflow $
36913994 "I just started parsing a record, but I got stuck here:"
36923995 ,
3693− D.fillSep
3694− ["Records","look","like",D.dullyellow "{ x = 3, y = 4 },"
3695− ,"so","I","was","expecting","to","see","a","field","name","next."
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
36964006 ]
36974007 )
36984008
@@ -3701,7 +4011,7 @@ toRecordReport source context record startRow startCol =
37014011 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
37024012 region = toRegion row col
37034013 in
3704− Report.Report "UNFINISHED RECORD" region [] $
4014+ Report.Report "PROBLEM IN RECORD" region [] $
37054015 Code.toSnippet source surroundings (Just region)
37064016 (
37074017 D.reflow $
@@ -3736,22 +4046,67 @@ toRecordReport source context record startRow startCol =
37364046 \ that is a reserved word. Try using a different name!"
37374047 )
37384048
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+
37394088 _ ->
37404089 let
37414090 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
37424091 region = toRegion row col
37434092 in
3744− Report.Report "UNFINISHED RECORD" region [] $
4093+ Report.Report "PROBLEM IN RECORD" region [] $
37454094 Code.toSnippet source surroundings (Just region)
37464095 (
37474096 D.reflow $
3748− "I am partway through parsing a record, but I got stuck after that last comma:"
4097+ "I am partway through parsing a record, but I got stuck here:"
37494098 ,
3750− addNoteForRecordError $
3751− D.reflow $
3752− "Trailing commas are not allowed in records, so I was expecting to see another\
3753− \ record field defined next. If you are done defining the record, the fix may\
3754− \ be to delete that last comma?"
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+ ]
37554110 )
37564111
37574112 RecordEquals row col ->
@@ -3759,17 +4114,19 @@ toRecordReport source context record startRow startCol =
37594114 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
37604115 region = toRegion row col
37614116 in
3762− Report.Report "UNFINISHED RECORD" region [] $
4117+ Report.Report "PROBLEM IN RECORD" region [] $
37634118 Code.toSnippet source surroundings (Just region)
37644119 (
37654120 D.reflow $
37664121 "I am partway through parsing a record, but I got stuck here:"
37674122 ,
3768− addNoteForRecordError $
3769− D.fillSep $
3770− ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
3771− ,"an","equals","sign","next.","So","try","putting","an",D.green "=","sign","here?"
3772− ]
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+ ]
37734130 )
37744131
37754132 RecordExpr expr row col ->
@@ -3789,29 +4146,54 @@ toRecordReport source context record startRow startCol =
37894146 D.reflow $
37904147 "I just saw the opening curly brace of a record, but then I got stuck here:"
37914148 ,
3792− addNoteForRecordIndentError $
3793− D.fillSep $
3794− ["I","am","expecting","a","record","like",D.dullyellow "{ x = 3, y = 4 }","here."
3795− ,"Try","defining","some","fields","of","your","own?"
3796− ]
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+ ]
37974156 )
37984157
37994158 RecordIndentEnd row col ->
3800− let
3801− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3802− region = toRegion row col
3803− in
3804− Report.Report "UNFINISHED RECORD" region [] $
3805− Code.toSnippet source surroundings (Just region)
3806− (
3807− D.reflow $
3808− "I was expecting to see a closing curly brace next:"
3809− ,
3810− addNoteForRecordIndentError $
3811− D.fillSep $
3812− ["Try","putting","an",D.green "}","and","see","if","that","helps?"
3813− ]
3814− )
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+ )
38154197
38164198 RecordIndentField row col ->
38174199 let
@@ -3824,11 +4206,13 @@ toRecordReport source context record startRow startCol =
38244206 D.reflow $
38254207 "I am partway through parsing a record, but I got stuck after that last comma:"
38264208 ,
3827− addNoteForRecordError $
3828− D.reflow $
3829− "Trailing commas are not allowed in records, so the fix may be to\
3830− \ delete that last comma? Or maybe you were in the middle of defining\
3831− \ an additional field?"
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+ ]
38324216 )
38334217
38344218 RecordIndentEquals row col ->
@@ -3843,10 +4227,12 @@ toRecordReport source context record startRow startCol =
38434227 "I am partway through parsing a record. I just saw a record\
38444228 \ field, so I was expecting to see an equals sign next:"
38454229 ,
3846− addNoteForRecordIndentError $
3847− D.fillSep $
3848− ["Try","putting","an",D.green "=","followed","by","an","expression?"
3849− ]
4230+ D.stack
4231+ [ D.fillSep $
4232+ ["Try","putting","an",D.green "=","followed","by","an","expression?"
4233+ ]
4234+ , noteForRecordIndentError
4235+ ]
38504236 )
38514237
38524238 RecordIndentExpr row col ->
@@ -3860,52 +4246,48 @@ toRecordReport source context record startRow startCol =
38604246 D.reflow $
38614247 "I am partway through parsing a record, and I was expecting to run into an expression next:"
38624248 ,
3863− addNoteForRecordIndentError $
3864− D.fillSep $
3865− ["Try","putting","something","like"
3866− ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
3867− ]
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+ ]
38684256 )
38694257
38704258
3871−addNoteForRecordError :: D.Doc -> D.Doc
3872−addNoteForRecordError normalRecommendation =
4259+noteForRecordError :: D.Doc
4260+noteForRecordError =
38734261 D.stack $
3874− normalRecommendation
3875− :
38764262 [ D.toSimpleNote
38774263 "If you are trying to define a record across multiple lines, I recommend using this format:"
38784264 , D.indent 4 $ D.vcat $
3879− [ "{ name = \"Alice\""
3880− , ", age = 42"
3881− , ", height = 1.75"
4265+ [ "{ name = " <> D.dullyellow "\"Alice\""
4266+ , ", age = " <> D.dullyellow "42"
4267+ , ", height = " <> D.dullyellow "1.75"
38824268 , "}"
38834269 ]
38844270 , D.reflow $
3885− "Notice that each line starts with some indentation. Usually two or four spaces. I\
3886− \ know this style can be jarring for people coming from C-like syntax, but folks generally\
3887− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4271+ "Notice that each line starts with some indentation. Usually two or four spaces.\
4272+ \ This is the stylistic convention in the Elm ecosystem."
38884273 ]
38894274
38904275
3891−addNoteForRecordIndentError :: D.Doc -> D.Doc
3892−addNoteForRecordIndentError normalRecommendation =
3893− D.stack $
3894− normalRecommendation
3895− :
4276+noteForRecordIndentError :: D.Doc
4277+noteForRecordIndentError =
4278+ D.stack
38964279 [ D.toSimpleNote
38974280 "I may be confused by indentation. For example, if you are trying to define\
38984281 \ a record across multiple lines, I recommend using this format:"
38994282 , D.indent 4 $ D.vcat $
3900− [ "{ name = \"Alice\""
3901− , ", age = 42"
3902− , ", height = 1.75"
4283+ [ "{ name = " <> D.dullyellow "\"Alice\""
4284+ , ", age = " <> D.dullyellow "42"
4285+ , ", height = " <> D.dullyellow "1.75"
39034286 , "}"
39044287 ]
39054288 , D.reflow $
3906− "Notice that each line starts with some indentation. Usually two or four spaces. I\
3907− \ know this style can be jarring for people coming from C-like syntax, but folks generally\
3908− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4289+ "Notice that each line starts with some indentation. Usually two or four spaces.\
4290+ \ This is the stylistic convention in the Elm ecosystem!"
39094291 ]
39104292
39114293
@@ -4094,15 +4476,14 @@ toListReport source context list startRow startCol =
40944476 , D.toSimpleNote
40954477 "I recommend using the following format for lists that span multiple lines:"
40964478 , D.indent 4 $ D.vcat $
4097− [ "[ \"Alice\""
4098− , ", \"Bob\""
4099− , ", \"Chuck\""
4479+ [ "[ " <> D.dullyellow "\"Alice\""
4480+ , ", " <> D.dullyellow "\"Bob\""
4481+ , ", " <> D.dullyellow "\"Chuck\""
41004482 , "]"
41014483 ]
41024484 , D.reflow $
4103− "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4104− \ This style can be jarring for people coming from C-like syntax, but folks generally\
4105− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4485+ "Notice that each line starts with some indentation. Usually two or four spaces.\
4486+ \ This is the stylistic convention in the Elm ecosystem."
41064487 ]
41074488 )
41084489
@@ -4155,15 +4536,14 @@ toListReport source context list startRow startCol =
41554536 "I may be confused by indentation. For example, if you are trying to define\
41564537 \ a list across multiple lines, I recommend using this format:"
41574538 , D.indent 4 $ D.vcat $
4158− [ "[ \"Alice\""
4159− , ", \"Bob\""
4160− , ", \"Chuck\""
4539+ [ "[ " <> D.dullyellow "\"Alice\""
4540+ , ", " <> D.dullyellow "\"Bob\""
4541+ , ", " <> D.dullyellow "\"Chuck\""
41614542 , "]"
41624543 ]
41634544 , D.reflow $
4164− "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4165− \ This style can be jarring for people coming from C-like syntax, but folks generally\
4166− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4545+ "Notice that each line starts with some indentation. Usually two or four spaces.\
4546+ \ This is the stylistic convention in the Elm ecosystem."
41674547 ]
41684548 )
41694549
@@ -4187,15 +4567,14 @@ toListReport source context list startRow startCol =
41874567 "I may be confused by indentation. For example, if you are trying to define\
41884568 \ a list across multiple lines, I recommend using this format:"
41894569 , D.indent 4 $ D.vcat $
4190− [ "[ \"Alice\""
4191− , ", \"Bob\""
4192− , ", \"Chuck\""
4570+ [ "[ " <> D.dullyellow "\"Alice\""
4571+ , ", " <> D.dullyellow "\"Bob\""
4572+ , ", " <> D.dullyellow "\"Chuck\""
41934573 , "]"
41944574 ]
41954575 , D.reflow $
4196− "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4197− \ This style can be jarring for people coming from C-like syntax, but folks generally\
4198− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4576+ "Notice that each line starts with some indentation. Usually two or four spaces.\
4577+ \ This is the stylistic convention in the Elm ecosystem."
41994578 ]
42004579 )
42014580
@@ -4216,15 +4595,14 @@ toListReport source context list startRow startCol =
42164595 , D.toSimpleNote
42174596 "I recommend using the following format for lists that span multiple lines:"
42184597 , D.indent 4 $ D.vcat $
4219− [ "[ \"Alice\""
4220− , ", \"Bob\""
4221− , ", \"Chuck\""
4598+ [ "[ " <> D.dullyellow "\"Alice\""
4599+ , ", " <> D.dullyellow "\"Bob\""
4600+ , ", " <> D.dullyellow "\"Chuck\""
42224601 , "]"
42234602 ]
42244603 , D.reflow $
4225− "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4226− \ This style can be jarring for people coming from C-like syntax, but folks generally\
4227− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4604+ "Notice that each line starts with some indentation. Usually two or four spaces.\
4605+ \ This is the stylistic convention in the Elm ecosystem."
42284606 ]
42294607 )
42304608
@@ -5097,22 +5475,64 @@ toTRecordReport source context record startRow startCol =
50975475 \ that is a reserved word. Try using a different name!"
50985476 )
50995477
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+
51005517 _ ->
51015518 let
51025519 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
51035520 region = toRegion row col
51045521 in
5105− Report.Report "UNFINISHED RECORD TYPE" region [] $
5522+ Report.Report "PROBLEM IN RECORD TYPE" region [] $
51065523 Code.toSnippet source surroundings (Just region)
51075524 (
51085525 D.reflow $
5109− "I am partway through parsing a record type, but I got stuck after that last comma:"
5526+ "I am partway through parsing a record type, but I got stuck here:"
51105527 ,
5111− addNoteForRecordTypeError $
5112− D.reflow $
5113− "Trailing commas are not allowed in records, so I was expecting to see another\
5114− \ record field defined next. If you are done defining the record, the fix may\
5115− \ be to delete that last comma?"
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+ ]
51165536 )
51175537
51185538 TRecordColon row col ->
@@ -5126,11 +5546,13 @@ toTRecordReport source context record startRow startCol =
51265546 D.reflow $
51275547 "I am partway through parsing a record type, but I got stuck here:"
51285548 ,
5129− addNoteForRecordTypeError $
5130− D.fillSep $
5131− ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
5132− ,"a","colon","next.","So","try","putting","an",D.green ":","sign","here?"
5133− ]
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+ ]
51345556 )
51355557
51365558 TRecordType tipe row col ->
@@ -5150,29 +5572,54 @@ toTRecordReport source context record startRow startCol =
51505572 D.reflow $
51515573 "I just saw the opening curly brace of a record type, but then I got stuck here:"
51525574 ,
5153− addNoteForRecordTypeIndentError $
5154− D.fillSep $
5155− ["I","am","expecting","a","record","like",D.dullyellow "{ name : String, age : Int }","here."
5156− ,"Try","defining","some","fields","of","your","own?"
5157− ]
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+ ]
51585582 )
51595583
51605584 TRecordIndentEnd row col ->
5161− let
5162− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5163− region = toRegion row col
5164− in
5165− Report.Report "UNFINISHED RECORD TYPE" region [] $
5166− Code.toSnippet source surroundings (Just region)
5167− (
5168− D.reflow $
5169− "I was expecting to see a closing curly brace next:"
5170− ,
5171− addNoteForRecordTypeIndentError $
5172− D.fillSep $
5173− ["Try","putting","an",D.green "}","and","see","if","that","helps?"
5174− ]
5175− )
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+ )
51765623
51775624 TRecordIndentField row col ->
51785625 let
@@ -5185,11 +5632,13 @@ toTRecordReport source context record startRow startCol =
51855632 D.reflow $
51865633 "I am partway through parsing a record type, but I got stuck after that last comma:"
51875634 ,
5188− addNoteForRecordTypeIndentError $
5189− D.reflow $
5190− "Trailing commas are not allowed in record types, so the fix may be to\
5191− \ delete that last comma? Or maybe you were in the middle of defining\
5192− \ an additional field?"
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+ ]
51935642 )
51945643
51955644 TRecordIndentColon row col ->
@@ -5204,10 +5653,12 @@ toTRecordReport source context record startRow startCol =
52045653 "I am partway through parsing a record type. I just saw a record\
52055654 \ field, so I was expecting to see a colon next:"
52065655 ,
5207− addNoteForRecordTypeIndentError $
5208− D.fillSep $
5209− ["Try","putting","an",D.green ":","followed","by","a","type?"
5210− ]
5656+ D.stack
5657+ [ D.fillSep $
5658+ ["Try","putting","an",D.green ":","followed","by","a","type?"
5659+ ]
5660+ , noteForRecordTypeIndentError
5661+ ]
52115662 )
52125663
52135664 TRecordIndentType row col ->
@@ -5221,19 +5672,19 @@ toTRecordReport source context record startRow startCol =
52215672 D.reflow $
52225673 "I am partway through parsing a record type, and I was expecting to run into a type next:"
52235674 ,
5224− addNoteForRecordTypeIndentError $
5225− D.fillSep $
5226− ["Try","putting","something","like"
5227− ,D.dullyellow "Int","or",D.dullyellow "String","for","now?"
5228− ]
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+ ]
52295682 )
52305683
52315684
5232−addNoteForRecordTypeError :: D.Doc -> D.Doc
5233−addNoteForRecordTypeError normalRecommendation =
5685+noteForRecordTypeError :: D.Doc
5686+noteForRecordTypeError =
52345687 D.stack $
5235− normalRecommendation
5236− :
52375688 [ D.toSimpleNote
52385689 "If you are trying to define a record type across multiple lines, I recommend using this format:"
52395690 , D.indent 4 $ D.vcat $
@@ -5243,17 +5694,14 @@ addNoteForRecordTypeError normalRecommendation =
52435694 , "}"
52445695 ]
52455696 , D.reflow $
5246− "Notice that each line starts with some indentation. Usually two or four spaces. I\
5247− \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5248− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
5697+ "Notice that each line starts with some indentation. Usually two or four spaces.\
5698+ \ This is the stylistic convention in the Elm ecosystem."
52495699 ]
52505700
52515701
5252−addNoteForRecordTypeIndentError :: D.Doc -> D.Doc
5253−addNoteForRecordTypeIndentError normalRecommendation =
5702+noteForRecordTypeIndentError :: D.Doc
5703+noteForRecordTypeIndentError =
52545704 D.stack $
5255− normalRecommendation
5256− :
52575705 [ D.toSimpleNote
52585706 "I may be confused by indentation. For example, if you are trying to define\
52595707 \ a record type across multiple lines, I recommend using this format:"
@@ -5264,9 +5712,8 @@ addNoteForRecordTypeIndentError normalRecommendation =
52645712 , "}"
52655713 ]
52665714 , D.reflow $
5267− "Notice that each line starts with some indentation. Usually two or four spaces. I\
5268− \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5269− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
5715+ "Notice that each line starts with some indentation. Usually two or four spaces.\
5716+ \ This is the stylistic convention in the Elm ecosystem."
52705717 ]
52715718
52725719