@@ -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
@@ -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,156 @@ 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 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+ )
655725
656726 ModuleProblem row col ->
657727 let
@@ -797,11 +867,11 @@ toParseErrorReport source modul =
797867 [ D.reflow $
798868 "I am not sure what is going on, but I recommend starting an Elm\
799869 \ file with the following lines:"
800− , D.indent 4 $ D.vcat $
870+ , D.vcat
801871 [ D.fillSep [D.cyan "import","Html"]
802872 , ""
803− , "main ="
804− , " Html.text " <> D.dullyellow "\"Hello!\""
873+ , D.fillSep [D.green "main","="]
874+ , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
805875 ]
806876 , D.reflow $
807877 "You should be able to copy those lines directly into your file. Check out the\
@@ -830,12 +900,11 @@ toParseErrorReport source modul =
830900 , D.indent 4 $ D.vcat $
831901 [ D.fillSep [D.cyan "import","Dict"]
832902 , 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","(..)"]
903+ , D.fillSep [D.cyan "import","Html.Attributes"]
904+ , D.fillSep [D.cyan "import","Json.Decode"]
835905 ]
836906 , D.reflow $
837907 "Notice that the module names all start with capital letters. That is required!"
838− , D.reflowLink "Read" "imports" "to learn more."
839908 ]
840909 )
841910
@@ -862,7 +931,6 @@ toParseErrorReport source modul =
862931 ]
863932 , D.reflow $
864933 "Notice that the alias always starts with a capital letter. That is required!"
865− , D.reflowLink "Read" "imports" "to learn more."
866934 ]
867935 )
868936
@@ -925,192 +993,6 @@ toParseErrorReport source modul =
925993
926994
927995
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−
1114996-- IMPORTS
1115997
1116998
@@ -1136,7 +1018,6 @@ toImportReport source row col =
11361018 ]
11371019 , D.reflow $
11381020 "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."
11401021 ]
11411022 )
11421023
@@ -1443,7 +1324,106 @@ toDeclarationsReport :: Code.Source -> Decl -> Report.Report
14431324toDeclarationsReport source decl =
14441325 case decl of
14451326 DeclStart row col ->
1446− toDeclStartReport source 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+ )
14471427
14481428 DeclSpace space row col ->
14491429 toSpaceReport source space row col
@@ -1473,165 +1453,6 @@ toDeclarationsReport source decl =
14731453 )
14741454
14751455
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−
16351456
16361457-- PORT
16371458
@@ -1758,7 +1579,7 @@ toPortReport source port_ startRow startCol =
17581579 [ D.reflow $
17591580 "I was expecting to see a type next. Here are examples of outgoing and\
17601581 \ incoming ports for reference:"
1761− , D.indent 4 $ D.vcat $
1582+ , D.vcat
17621583 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
17631584 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
17641585 ]
@@ -1777,7 +1598,7 @@ portNote =
17771598 D.stack
17781599 [ D.toSimpleNote $
17791600 "Here are some example `port` declarations for reference:"
1780− , D.indent 4 $ D.vcat $
1601+ , D.vcat
17811602 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
17821603 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
17831604 ]
@@ -1960,8 +1781,8 @@ typeAliasNote =
19601781 [ D.toSimpleNote $
19611782 "Here is an example of a valid `type alias` for reference:"
19621783 , D.vcat $
1963− [ D.indent 4 $ D.fillSep [D.cyan "type",D.cyan "alias","Person","="]
1964− , D.indent 6 $ D.vcat $
1784+ [ D.indent 0 $ D.fillSep [D.cyan "type",D.cyan "alias",D.green "Person","="]
1785+ , D.indent 2 $ D.vcat $
19651786 ["{ name : String"
19661787 ,", age : Int"
19671788 ,", height : Float"
@@ -2161,10 +1982,10 @@ customTypeNote =
21611982 [ D.toSimpleNote $
21621983 "Here is an example of a valid `type` declaration for reference:"
21631984 , 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"]
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"]
21681989 ]
21691990 , D.reflow $
21701991 "This defines a new `Status` type with three variants. This could be useful if\
@@ -2236,10 +2057,10 @@ toDeclDefReport source name declDef startRow startCol =
22362057 ,"a","type","annotation.","It","could","be","something","else","though,","so"
22372058 ,"here","is","a","valid","definition","for","reference:"
22382059 ]
2239− , D.indent 4 $ D.vcat $
2240− [ "greet : String -> String"
2241− , "greet name ="
2242− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
2060+ , D.vcat
2061+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2062+ , D.fillSep [D.green "add","x","y","="]
2063+ , D.fillSep [" ","x","+","y"]
22432064 ]
22442065 , D.reflow $
22452066 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -2261,10 +2082,10 @@ toDeclDefReport source name declDef startRow startCol =
22612082 [ D.reflow $
22622083 "I am not sure what is going wrong exactly, so here is a valid\
22632084 \ 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 "\"!\""
2085+ , D.vcat
2086+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2087+ , D.fillSep [D.green "add","x","y","="]
2088+ , D.fillSep [" ","x","+","y"]
22682089 ]
22692090 , D.reflow $
22702091 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -2286,10 +2107,10 @@ toDeclDefReport source name declDef startRow startCol =
22862107 [ D.reflow $
22872108 "I am not sure what is going wrong exactly, so here is a valid\
22882109 \ 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 "\"!\""
2110+ , D.vcat
2111+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2112+ , D.fillSep [D.green "add","x","y","="]
2113+ , D.fillSep [" ","x","+","y"]
22932114 ]
22942115 , D.reflow $
22952116 "Try to use that format!"
@@ -2404,10 +2225,10 @@ declDefNote =
24042225 D.stack
24052226 [ D.reflow $
24062227 "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 "\"!\""
2228+ , D.vcat
2229+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2230+ , D.fillSep [D.green "add","x","y","="]
2231+ , D.fillSep [" ","x","+","y"]
24112232 ]
24122233 , D.reflow $
24132234 "The top line (called a \"type annotation\") is optional. You can leave it off\
@@ -2591,7 +2412,7 @@ toExprReport source context expr startRow startCol =
25912412 ,"give","a","more","specific","hint!"
25922413 ]
25932414 , D.toSimpleNote $
2594− "This can also happen if I run into reserved words like `let` or `as` unexpectedly.\
2415+ "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
25952416 \ Or if I run into operators in unexpected spots. Point is, there are a\
25962417 \ couple ways I can get confused and give sort of weird advice!"
25972418 ]
@@ -2740,15 +2561,17 @@ toStringReport source string row col =
27402561 , D.toSimpleNote $
27412562 "For a string that spans multiple lines, you can use the multi-line string\
27422563 \ 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− , "\"\"\""
2564+ , D.vcat
2565+ [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
2566+ , mempty
2567+ , D.dullyellow "# Multi-line Strings"
2568+ , mempty
2569+ , D.dullyellow "- start with triple double quotes"
2570+ , D.dullyellow "- write whatever you want"
2571+ , D.dullyellow "- no need to escape newlines or double quotes"
2572+ , D.dullyellow "- end with triple double quotes"
2573+ , mempty
2574+ , D.dullyellow "\"\"\""
27522575 ]
27532576 ]
27542577 )
@@ -2767,15 +2590,17 @@ toStringReport source string row col =
27672590 [ D.reflow "Add a \"\"\" somewhere after this to end the string."
27682591 , D.toSimpleNote $
27692592 "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− , "\"\"\""
2593+ , D.vcat
2594+ [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
2595+ , mempty
2596+ , D.dullyellow "# Multi-line Strings"
2597+ , mempty
2598+ , D.dullyellow "- start with triple double quotes"
2599+ , D.dullyellow "- write whatever you want"
2600+ , D.dullyellow "- no need to escape newlines or double quotes"
2601+ , D.dullyellow "- end with triple double quotes"
2602+ , mempty
2603+ , D.dullyellow "\"\"\""
27792604 ]
27802605 ]
27812606 )
@@ -3035,15 +2860,11 @@ toOperatorReport source context operator row col =
30352860 else
30362861 (
30372862 D.reflow $
3038− "I was partway through parsing an expression when I got stuck on this arrow:"
2863+ "I was not expecting an arrow here:"
30392864 ,
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− ]
2865+ D.reflow $
2866+ "Arrows should only appear in `case` expressions and anonymous functions. Maybe\
2867+ \ you want > or >= instead?"
30472868 )
30482869
30492870 BadEquals ->
@@ -3240,8 +3061,8 @@ toUnfinishLetReport source row col startRow startCol message =
32403061 [ message
32413062 , D.toSimpleNote $
32423063 "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","="]
3064+ , D.vcat $
3065+ [ D.indent 0 $ D.fillSep [D.green "viewPerson","person","="]
32453066 , D.indent 2 $ D.fillSep [D.cyan "let"]
32463067 , D.indent 4 $ D.fillSep ["fullName","="]
32473068 , D.indent 6 $ D.fillSep ["person.firstName","++",D.dullyellow "\" \"","++","person.lastName"]
@@ -3359,10 +3180,10 @@ toLetDefReport source name def startRow startCol =
33593180 ,"a","type","annotation.","It","could","be","something","else","though,","so"
33603181 ,"here","is","a","valid","definition","for","reference:"
33613182 ]
3362− , D.indent 4 $ D.vcat $
3363− [ "greet : String -> String"
3364− , "greet name ="
3365− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
3183+ , D.vcat
3184+ [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3185+ , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3186+ , D.indent 6 $ D.fillSep ["x","+","y"]
33663187 ]
33673188 , D.reflow $
33683189 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -3384,10 +3205,10 @@ toLetDefReport source name def startRow startCol =
33843205 [ D.reflow $
33853206 "I am not sure what is going wrong exactly, so here is a valid\
33863207 \ 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 "\"!\""
3208+ , D.vcat
3209+ [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3210+ , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3211+ , D.indent 6 $ D.fillSep ["x","+","y"]
33913212 ]
33923213 , D.reflow $
33933214 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -3409,10 +3230,10 @@ toLetDefReport source name def startRow startCol =
34093230 [ D.reflow $
34103231 "I am not sure what is going wrong exactly, so here is a valid\
34113232 \ 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 "\"!\""
3233+ , D.vcat
3234+ [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3235+ , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3236+ , D.indent 4 $ D.fillSep ["x","+","y"]
34163237 ]
34173238 , D.reflow $
34183239 "Try to use that format!"
@@ -3502,10 +3323,10 @@ defNote =
35023323 D.stack
35033324 [ D.reflow $
35043325 "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 "\"!\""
3326+ , D.vcat
3327+ [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3328+ , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3329+ , D.indent 6 $ D.fillSep ["x","+","y"]
35093330 ]
35103331 , D.reflow $
35113332 "The top line (called a \"type annotation\") is optional. You can leave it off\
@@ -3918,43 +3739,23 @@ toIfReport source context if_ startRow startCol =
39183739 )
39193740
39203741 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− )
3742+ let
3743+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3744+ region = toRegion row col
3745+ in
3746+ Report.Report "UNFINISHED IF" region [] $
3747+ Code.toSnippet source surroundings (Just region)
3748+ (
3749+ D.reflow $
3750+ "I was expecting to see an `else` branch after this:"
3751+ ,
3752+ D.stack
3753+ [ D.reflow $
3754+ "I know what to do when the condition is `True`, but not when it is `False`."
3755+ , D.fillSep
3756+ ["Add","an",D.cyan "else","branch","to","handle","that","scenario!"]
3757+ ]
3758+ )
39583759
39593760
39603761
@@ -3987,22 +3788,15 @@ toRecordReport source context record startRow startCol =
39873788 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
39883789 region = toRegion row col
39893790 in
3990− Report.Report "PROBLEM IN RECORD" region [] $
3791+ Report.Report "UNFINISHED RECORD" region [] $
39913792 Code.toSnippet source surroundings (Just region)
39923793 (
39933794 D.reflow $
39943795 "I just started parsing a record, but I got stuck here:"
39953796 ,
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
3797+ D.fillSep
3798+ ["Records","look","like",D.dullyellow "{ x = 3, y = 4 },"
3799+ ,"so","I","was","expecting","to","see","a","field","name","next."
40063800 ]
40073801 )
40083802
@@ -4011,7 +3805,7 @@ toRecordReport source context record startRow startCol =
40113805 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
40123806 region = toRegion row col
40133807 in
4014− Report.Report "PROBLEM IN RECORD" region [] $
3808+ Report.Report "UNFINISHED RECORD" region [] $
40153809 Code.toSnippet source surroundings (Just region)
40163810 (
40173811 D.reflow $
@@ -4046,67 +3840,22 @@ toRecordReport source context record startRow startCol =
40463840 \ that is a reserved word. Try using a different name!"
40473841 )
40483842
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−
40883843 _ ->
40893844 let
40903845 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
40913846 region = toRegion row col
40923847 in
4093− Report.Report "PROBLEM IN RECORD" region [] $
3848+ Report.Report "UNFINISHED RECORD" region [] $
40943849 Code.toSnippet source surroundings (Just region)
40953850 (
40963851 D.reflow $
4097− "I am partway through parsing a record, but I got stuck here:"
3852+ "I am partway through parsing a record, but I got stuck after that last comma:"
40983853 ,
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− ]
3854+ addNoteForRecordError $
3855+ D.reflow $
3856+ "Trailing commas are not allowed in records, so I was expecting to see another\
3857+ \ record field defined next. If you are done defining the record, the fix may\
3858+ \ be to delete that last comma?"
41103859 )
41113860
41123861 RecordEquals row col ->
@@ -4114,19 +3863,17 @@ toRecordReport source context record startRow startCol =
41143863 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
41153864 region = toRegion row col
41163865 in
4117− Report.Report "PROBLEM IN RECORD" region [] $
3866+ Report.Report "UNFINISHED RECORD" region [] $
41183867 Code.toSnippet source surroundings (Just region)
41193868 (
41203869 D.reflow $
41213870 "I am partway through parsing a record, but I got stuck here:"
41223871 ,
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− ]
3872+ addNoteForRecordError $
3873+ D.fillSep $
3874+ ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
3875+ ,"an","equals","sign","next.","So","try","putting","an",D.green "=","sign","here?"
3876+ ]
41303877 )
41313878
41323879 RecordExpr expr row col ->
@@ -4146,54 +3893,29 @@ toRecordReport source context record startRow startCol =
41463893 D.reflow $
41473894 "I just saw the opening curly brace of a record, but then I got stuck here:"
41483895 ,
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− ]
3896+ addNoteForRecordIndentError $
3897+ D.fillSep $
3898+ ["I","am","expecting","a","record","like",D.dullyellow "{ x = 3, y = 4 }","here."
3899+ ,"Try","defining","some","fields","of","your","own?"
3900+ ]
41563901 )
41573902
41583903 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− )
3904+ let
3905+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3906+ region = toRegion row col
3907+ in
3908+ Report.Report "UNFINISHED RECORD" region [] $
3909+ Code.toSnippet source surroundings (Just region)
3910+ (
3911+ D.reflow $
3912+ "I was expecting to see a closing curly brace next:"
3913+ ,
3914+ addNoteForRecordIndentError $
3915+ D.fillSep $
3916+ ["Try","putting","an",D.green "}","and","see","if","that","helps?"
3917+ ]
3918+ )
41973919
41983920 RecordIndentField row col ->
41993921 let
@@ -4206,13 +3928,11 @@ toRecordReport source context record startRow startCol =
42063928 D.reflow $
42073929 "I am partway through parsing a record, but I got stuck after that last comma:"
42083930 ,
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− ]
3931+ addNoteForRecordError $
3932+ D.reflow $
3933+ "Trailing commas are not allowed in records, so the fix may be to\
3934+ \ delete that last comma? Or maybe you were in the middle of defining\
3935+ \ an additional field?"
42163936 )
42173937
42183938 RecordIndentEquals row col ->
@@ -4227,12 +3947,10 @@ toRecordReport source context record startRow startCol =
42273947 "I am partway through parsing a record. I just saw a record\
42283948 \ field, so I was expecting to see an equals sign next:"
42293949 ,
4230− D.stack
4231− [ D.fillSep $
4232− ["Try","putting","an",D.green "=","followed","by","an","expression?"
4233− ]
4234− , noteForRecordIndentError
4235− ]
3950+ addNoteForRecordIndentError $
3951+ D.fillSep $
3952+ ["Try","putting","an",D.green "=","followed","by","an","expression?"
3953+ ]
42363954 )
42373955
42383956 RecordIndentExpr row col ->
@@ -4246,48 +3964,52 @@ toRecordReport source context record startRow startCol =
42463964 D.reflow $
42473965 "I am partway through parsing a record, and I was expecting to run into an expression next:"
42483966 ,
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− ]
3967+ addNoteForRecordIndentError $
3968+ D.fillSep $
3969+ ["Try","putting","something","like"
3970+ ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
3971+ ]
42563972 )
42573973
42583974
4259−noteForRecordError :: D.Doc
4260−noteForRecordError =
3975+addNoteForRecordError :: D.Doc -> D.Doc
3976+addNoteForRecordError normalRecommendation =
42613977 D.stack $
3978+ normalRecommendation
3979+ :
42623980 [ D.toSimpleNote
42633981 "If you are trying to define a record across multiple lines, I recommend using this format:"
42643982 , D.indent 4 $ D.vcat $
4265− [ "{ name = " <> D.dullyellow "\"Alice\""
4266− , ", age = " <> D.dullyellow "42"
4267− , ", height = " <> D.dullyellow "1.75"
3983+ [ "{ name = \"Alice\""
3984+ , ", age = 42"
3985+ , ", height = 1.75"
42683986 , "}"
42693987 ]
42703988 , 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."
3989+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
3990+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
3991+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
42733992 ]
42743993
42753994
4276−noteForRecordIndentError :: D.Doc
4277−noteForRecordIndentError =
4278− D.stack
3995+addNoteForRecordIndentError :: D.Doc -> D.Doc
3996+addNoteForRecordIndentError normalRecommendation =
3997+ D.stack $
3998+ normalRecommendation
3999+ :
42794000 [ D.toSimpleNote
42804001 "I may be confused by indentation. For example, if you are trying to define\
42814002 \ a record across multiple lines, I recommend using this format:"
42824003 , D.indent 4 $ D.vcat $
4283− [ "{ name = " <> D.dullyellow "\"Alice\""
4284− , ", age = " <> D.dullyellow "42"
4285− , ", height = " <> D.dullyellow "1.75"
4004+ [ "{ name = \"Alice\""
4005+ , ", age = 42"
4006+ , ", height = 1.75"
42864007 , "}"
42874008 ]
42884009 , 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!"
4010+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
4011+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
4012+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
42914013 ]
42924014
42934015
@@ -4476,14 +4198,15 @@ toListReport source context list startRow startCol =
44764198 , D.toSimpleNote
44774199 "I recommend using the following format for lists that span multiple lines:"
44784200 , D.indent 4 $ D.vcat $
4479− [ "[ " <> D.dullyellow "\"Alice\""
4480− , ", " <> D.dullyellow "\"Bob\""
4481− , ", " <> D.dullyellow "\"Chuck\""
4201+ [ "[ \"Alice\""
4202+ , ", \"Bob\""
4203+ , ", \"Chuck\""
44824204 , "]"
44834205 ]
44844206 , 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."
4207+ "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4208+ \ This style can be jarring for people coming from C-like syntax, but folks generally\
4209+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
44874210 ]
44884211 )
44894212
@@ -4536,14 +4259,15 @@ toListReport source context list startRow startCol =
45364259 "I may be confused by indentation. For example, if you are trying to define\
45374260 \ a list across multiple lines, I recommend using this format:"
45384261 , D.indent 4 $ D.vcat $
4539− [ "[ " <> D.dullyellow "\"Alice\""
4540− , ", " <> D.dullyellow "\"Bob\""
4541− , ", " <> D.dullyellow "\"Chuck\""
4262+ [ "[ \"Alice\""
4263+ , ", \"Bob\""
4264+ , ", \"Chuck\""
45424265 , "]"
45434266 ]
45444267 , 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."
4268+ "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4269+ \ This style can be jarring for people coming from C-like syntax, but folks generally\
4270+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
45474271 ]
45484272 )
45494273
@@ -4567,14 +4291,15 @@ toListReport source context list startRow startCol =
45674291 "I may be confused by indentation. For example, if you are trying to define\
45684292 \ a list across multiple lines, I recommend using this format:"
45694293 , D.indent 4 $ D.vcat $
4570− [ "[ " <> D.dullyellow "\"Alice\""
4571− , ", " <> D.dullyellow "\"Bob\""
4572− , ", " <> D.dullyellow "\"Chuck\""
4294+ [ "[ \"Alice\""
4295+ , ", \"Bob\""
4296+ , ", \"Chuck\""
45734297 , "]"
45744298 ]
45754299 , 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."
4300+ "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4301+ \ This style can be jarring for people coming from C-like syntax, but folks generally\
4302+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
45784303 ]
45794304 )
45804305
@@ -4595,14 +4320,15 @@ toListReport source context list startRow startCol =
45954320 , D.toSimpleNote
45964321 "I recommend using the following format for lists that span multiple lines:"
45974322 , D.indent 4 $ D.vcat $
4598− [ "[ " <> D.dullyellow "\"Alice\""
4599− , ", " <> D.dullyellow "\"Bob\""
4600− , ", " <> D.dullyellow "\"Chuck\""
4323+ [ "[ \"Alice\""
4324+ , ", \"Bob\""
4325+ , ", \"Chuck\""
46014326 , "]"
46024327 ]
46034328 , 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."
4329+ "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4330+ \ This style can be jarring for people coming from C-like syntax, but folks generally\
4331+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
46064332 ]
46074333 )
46084334
@@ -5475,64 +5201,22 @@ toTRecordReport source context record startRow startCol =
54755201 \ that is a reserved word. Try using a different name!"
54765202 )
54775203
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−
55175204 _ ->
55185205 let
55195206 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
55205207 region = toRegion row col
55215208 in
5522− Report.Report "PROBLEM IN RECORD TYPE" region [] $
5209+ Report.Report "UNFINISHED RECORD TYPE" region [] $
55235210 Code.toSnippet source surroundings (Just region)
55245211 (
55255212 D.reflow $
5526− "I am partway through parsing a record type, but I got stuck here:"
5213+ "I am partway through parsing a record type, but I got stuck after that last comma:"
55275214 ,
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− ]
5215+ addNoteForRecordTypeError $
5216+ D.reflow $
5217+ "Trailing commas are not allowed in records, so I was expecting to see another\
5218+ \ record field defined next. If you are done defining the record, the fix may\
5219+ \ be to delete that last comma?"
55365220 )
55375221
55385222 TRecordColon row col ->
@@ -5546,13 +5230,11 @@ toTRecordReport source context record startRow startCol =
55465230 D.reflow $
55475231 "I am partway through parsing a record type, but I got stuck here:"
55485232 ,
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− ]
5233+ addNoteForRecordTypeError $
5234+ D.fillSep $
5235+ ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
5236+ ,"a","colon","next.","So","try","putting","an",D.green ":","sign","here?"
5237+ ]
55565238 )
55575239
55585240 TRecordType tipe row col ->
@@ -5572,54 +5254,29 @@ toTRecordReport source context record startRow startCol =
55725254 D.reflow $
55735255 "I just saw the opening curly brace of a record type, but then I got stuck here:"
55745256 ,
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− ]
5257+ addNoteForRecordTypeIndentError $
5258+ D.fillSep $
5259+ ["I","am","expecting","a","record","like",D.dullyellow "{ name : String, age : Int }","here."
5260+ ,"Try","defining","some","fields","of","your","own?"
5261+ ]
55825262 )
55835263
55845264 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− )
5265+ let
5266+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5267+ region = toRegion row col
5268+ in
5269+ Report.Report "UNFINISHED RECORD TYPE" region [] $
5270+ Code.toSnippet source surroundings (Just region)
5271+ (
5272+ D.reflow $
5273+ "I was expecting to see a closing curly brace next:"
5274+ ,
5275+ addNoteForRecordTypeIndentError $
5276+ D.fillSep $
5277+ ["Try","putting","an",D.green "}","and","see","if","that","helps?"
5278+ ]
5279+ )
56235280
56245281 TRecordIndentField row col ->
56255282 let
@@ -5632,13 +5289,11 @@ toTRecordReport source context record startRow startCol =
56325289 D.reflow $
56335290 "I am partway through parsing a record type, but I got stuck after that last comma:"
56345291 ,
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− ]
5292+ addNoteForRecordTypeIndentError $
5293+ D.reflow $
5294+ "Trailing commas are not allowed in record types, so the fix may be to\
5295+ \ delete that last comma? Or maybe you were in the middle of defining\
5296+ \ an additional field?"
56425297 )
56435298
56445299 TRecordIndentColon row col ->
@@ -5653,12 +5308,10 @@ toTRecordReport source context record startRow startCol =
56535308 "I am partway through parsing a record type. I just saw a record\
56545309 \ field, so I was expecting to see a colon next:"
56555310 ,
5656− D.stack
5657− [ D.fillSep $
5658− ["Try","putting","an",D.green ":","followed","by","a","type?"
5659− ]
5660− , noteForRecordTypeIndentError
5661− ]
5311+ addNoteForRecordTypeIndentError $
5312+ D.fillSep $
5313+ ["Try","putting","an",D.green ":","followed","by","a","type?"
5314+ ]
56625315 )
56635316
56645317 TRecordIndentType row col ->
@@ -5672,19 +5325,19 @@ toTRecordReport source context record startRow startCol =
56725325 D.reflow $
56735326 "I am partway through parsing a record type, and I was expecting to run into a type next:"
56745327 ,
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− ]
5328+ addNoteForRecordTypeIndentError $
5329+ D.fillSep $
5330+ ["Try","putting","something","like"
5331+ ,D.dullyellow "Int","or",D.dullyellow "String","for","now?"
5332+ ]
56825333 )
56835334
56845335
5685−noteForRecordTypeError :: D.Doc
5686−noteForRecordTypeError =
5336+addNoteForRecordTypeError :: D.Doc -> D.Doc
5337+addNoteForRecordTypeError normalRecommendation =
56875338 D.stack $
5339+ normalRecommendation
5340+ :
56885341 [ D.toSimpleNote
56895342 "If you are trying to define a record type across multiple lines, I recommend using this format:"
56905343 , D.indent 4 $ D.vcat $
@@ -5694,14 +5347,17 @@ noteForRecordTypeError =
56945347 , "}"
56955348 ]
56965349 , 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."
5350+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
5351+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5352+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
56995353 ]
57005354
57015355
5702−noteForRecordTypeIndentError :: D.Doc
5703−noteForRecordTypeIndentError =
5356+addNoteForRecordTypeIndentError :: D.Doc -> D.Doc
5357+addNoteForRecordTypeIndentError normalRecommendation =
57045358 D.stack $
5359+ normalRecommendation
5360+ :
57055361 [ D.toSimpleNote
57065362 "I may be confused by indentation. For example, if you are trying to define\
57075363 \ a record type across multiple lines, I recommend using this format:"
@@ -5712,8 +5368,9 @@ noteForRecordTypeIndentError =
57125368 , "}"
57135369 ]
57145370 , 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."
5371+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
5372+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5373+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
57175374 ]
57185375
57195376