@@ -69,6 +69,9 @@ data Error
69 | ModuleNameMismatch ModuleName.Raw (A.Located ModuleName.Raw)
69 | ModuleNameMismatch ModuleName.Raw (A.Located ModuleName.Raw)
70 | UnexpectedPort A.Region
70 | UnexpectedPort A.Region
71 | NoPorts A.Region
71 | NoPorts A.Region
72+ | NoPortsInPackage (A.Located Name.Name)
73+ | NoPortModulesInPackage A.Region
74+ | NoEffectsOutsideKernel A.Region
72 | ParseError Module
75 | ParseError Module
@@ -561,10 +564,84 @@ toReport source err =
567+ NoPortsInPackage (A.At region _) ->
568+ Report.Report "PACKAGES CANNOT HAVE PORTS" region [] $
569+ Code.toSnippet source region Nothing
572+ "Packages cannot declare any ports, so I am getting stuck here:"
576+ "Remove this port declaration."
577+ , noteForPortsInPackage
581+ NoPortModulesInPackage region ->
582+ Report.Report "PACKAGES CANNOT HAVE PORTS" region [] $
583+ Code.toSnippet source region Nothing
586+ "Packages cannot declare any ports, so I am getting stuck here:"
590+ ["Remove","the",D.cyan "port","keyword","and","I"
591+ ,"should","be","able","to","continue."
593+ , noteForPortsInPackage
597+ NoEffectsOutsideKernel region ->
598+ Report.Report "INVALID EFFECT MODULE" region [] $
599+ Code.toSnippet source region Nothing
602+ "It is not possible to declare an `effect module` outside the @elm organization,\
603+ \ so I am getting stuck here:"
607+ "Switch to a normal module declaration."
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."
564 ParseError modul ->
619 ParseError modul ->
565 toParseErrorReport source modul
620 toParseErrorReport source modul
623+noteForPortsInPackage :: D.Doc
624+noteForPortsInPackage =
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."
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."
568toParseErrorReport :: Code.Source -> Module -> Report.Report
645toParseErrorReport :: Code.Source -> Module -> Report.Report
569toParseErrorReport source modul =
646toParseErrorReport source modul =
570 case modul of
647 case modul of
@@ -572,156 +649,9 @@ toParseErrorReport source modul =
572 toSpaceReport source space row col
649 toSpaceReport source space row col
574 ModuleBadEnd row col ->
651 ModuleBadEnd row col ->
575− case Code.whatIsNext source row col of
652+ if col == 1
576− Code.Keyword keyword ->
653+ then toDeclStartReport source row col
577− let
654+ else toWeirdEndReport source row col
578− region = toKeywordRegion row col keyword
580− Report.Report "RESERVED WORD" region [] $
581− Code.toSnippet source region Nothing
584− "I got stuck on this reserved word:"
587− "The name `" ++ keyword ++ "` is reserved, so try using a different name?"
592− region = toKeywordRegion row col op
594− Report.Report "UNEXPECTED SYMBOL" region [] $
595− Code.toSnippet source region Nothing
598− "I ran into an unexpected symbol:"
601− "I was not expecting to see a " ++ op ++ " here. Try deleting it? Maybe\
602− \ I can give a better hint from there?"
605− Code.Close term bracket ->
607− region = toRegion row col
609− Report.Report ("UNEXPECTED " ++ map Char.toUpper term) region [] $
610− Code.toSnippet source region Nothing
613− "I ran into an unexpected " ++ term ++ ":"
616− "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
619− Code.Other maybeChar ->
621− region = toRegion row col
625− Report.Report "UNEXPECTED SEMICOLON" region [] $
626− Code.toSnippet source region Nothing
629− "I got stuck on this semicolon:"
632− [ D.reflow $ "Try removing it?"
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!"
644− Report.Report "UNEXPECTED COMMA" region [] $
645− Code.toSnippet source region Nothing
648− "I got stuck on this comma:"
652− "I do not think I am parsing a list or tuple right now. Try deleting the comma?"
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."
662− Report.Report "UNEXPECTED CHARACTER" region [] $
663− Code.toSnippet source region Nothing
666− "I got stuck on this character:"
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:"
674− [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
676− , D.dullyellow "# Multi-line Strings"
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"
683− , D.dullyellow "\"\"\""
686− "Otherwise I do not know what is going on! Try removing the character?"
691− Report.Report "UNEXPECTED SYMBOL" region [] $
692− Code.toSnippet source region Nothing
695− "I got stuck on this dollar sign:"
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."
703− Just c | elem c ['#','@','!','%','~'] ->
704− Report.Report "UNEXPECTED SYMBOL" region [] $
705− Code.toSnippet source region Nothing
708− "I got stuck on this symbol:"
711− "It is not used for anything in Elm syntax. Try removing it?"
715− Report.Report "SYNTAX PROBLEM" region [] $
716− Code.toSnippet source region Nothing
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."
726 ModuleProblem row col ->
656 ModuleProblem row col ->
@@ -867,11 +797,11 @@ toParseErrorReport source modul =
867 [ D.reflow $
797 [ D.reflow $
868 "I am not sure what is going on, but I recommend starting an Elm\
798 "I am not sure what is going on, but I recommend starting an Elm\
869 \ file with the following lines:"
799 \ file with the following lines:"
870− , D.vcat
800+ , D.indent 4 $ D.vcat $
871 [ D.fillSep [D.cyan "import","Html"]
801 [ D.fillSep [D.cyan "import","Html"]
873− , D.fillSep [D.green "main","="]
803+ , "main ="
874− , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
804+ , " Html.text " <> D.dullyellow "\"Hello!\""
876 , D.reflow $
806 , D.reflow $
877 "You should be able to copy those lines directly into your file. Check out the\
807 "You should be able to copy those lines directly into your file. Check out the\
@@ -900,11 +830,12 @@ toParseErrorReport source modul =
900 , D.indent 4 $ D.vcat $
830 , D.indent 4 $ D.vcat $
901 [ D.fillSep [D.cyan "import","Dict"]
831 [ D.fillSep [D.cyan "import","Dict"]
902 , D.fillSep [D.cyan "import","Maybe"]
832 , D.fillSep [D.cyan "import","Maybe"]
903− , D.fillSep [D.cyan "import","Html.Attributes"]
833+ , D.fillSep [D.cyan "import","Html.Attributes",D.cyan "as","A"]
904− , D.fillSep [D.cyan "import","Json.Decode"]
834+ , D.fillSep [D.cyan "import","Json.Decode",D.cyan "exposing","(..)"]
906 , D.reflow $
836 , D.reflow $
907 "Notice that the module names all start with capital letters. That is required!"
837 "Notice that the module names all start with capital letters. That is required!"
838+ , D.reflowLink "Read" "imports" "to learn more."
@@ -931,6 +862,7 @@ toParseErrorReport source modul =
932 , D.reflow $
863 , D.reflow $
933 "Notice that the alias always starts with a capital letter. That is required!"
864 "Notice that the alias always starts with a capital letter. That is required!"
865+ , D.reflowLink "Read" "imports" "to learn more."
@@ -993,6 +925,192 @@ toParseErrorReport source modul =
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 ->
936+ region = toKeywordRegion row col keyword
938+ Report.Report "RESERVED WORD" region [] $
939+ Code.toSnippet source region Nothing
942+ "I got stuck on this reserved word:"
945+ "The name `" ++ keyword ++ "` is reserved, so try using a different name?"
950+ region = toKeywordRegion row col op
952+ Report.Report "UNEXPECTED SYMBOL" region [] $
953+ Code.toSnippet source region Nothing
956+ "I ran into an unexpected symbol:"
959+ "I was not expecting to see a " ++ op ++ " here. Try deleting it? Maybe\
960+ \ I can give a better hint from there?"
963+ Code.Close term bracket ->
965+ region = toRegion row col
967+ Report.Report ("UNEXPECTED " ++ map Char.toUpper term) region [] $
968+ Code.toSnippet source region Nothing
971+ "I ran into an unexpected " ++ term ++ ":"
974+ "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
979+ region = toKeywordRegion row col (c:cs)
981+ Report.Report "UNEXPECTED NAME" region [] $
982+ Code.toSnippet source region Nothing
985+ "I got stuck on this name:"
988+ "It is confusing me a lot! Normally I can give fairly specific hints, but\
989+ \ something is really tripping me up this time."
994+ region = toKeywordRegion row col (c:cs)
996+ Report.Report "UNEXPECTED NAME" region [] $
997+ Code.toSnippet source region Nothing
1000+ "I got stuck on this name:"
1003+ "It is confusing me a lot! Normally I can give fairly specific hints, but\
1004+ \ something is really tripping me up this time."
1007+ Code.Other maybeChar ->
1009+ region = toRegion row col
1013+ Report.Report "UNEXPECTED SEMICOLON" region [] $
1014+ Code.toSnippet source region Nothing
1017+ "I got stuck on this semicolon:"
1020+ [ D.reflow $ "Try removing it?"
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!"
1032+ Report.Report "UNEXPECTED COMMA" region [] $
1033+ Code.toSnippet source region Nothing
1036+ "I got stuck on this comma:"
1040+ "I do not think I am parsing a list or tuple right now. Try deleting the comma?"
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."
1050+ Report.Report "UNEXPECTED CHARACTER" region [] $
1051+ Code.toSnippet source region Nothing
1054+ "I got stuck on this character:"
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 $
1063+ , "# Multi-line Strings"
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"
1072+ "Otherwise I do not know what is going on! Try removing the character?"
1077+ Report.Report "UNEXPECTED SYMBOL" region [] $
1078+ Code.toSnippet source region Nothing
1081+ "I got stuck on this dollar sign:"
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."
1089+ Just c | elem c ['#','@','!','%','~'] ->
1090+ Report.Report "UNEXPECTED SYMBOL" region [] $
1091+ Code.toSnippet source region Nothing
1094+ "I got stuck on this symbol:"
1097+ "It is not used for anything in Elm syntax. Try removing it?"
1101+ Report.Report "SYNTAX PROBLEM" region [] $
1102+ Code.toSnippet source region Nothing
1105+ "I got stuck here:"
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."
996-- IMPORTS
1114-- IMPORTS
@@ -1018,6 +1136,7 @@ toImportReport source row col =
1019 , D.reflow $
1137 , D.reflow $
1020 "You are probably trying to import a different module, but try to make it look like one of these examples!"
1138 "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."
@@ -1324,114 +1443,7 @@ toDeclarationsReport :: Code.Source -> Decl -> Report.Report
1324toDeclarationsReport source decl =
1443toDeclarationsReport source decl =
1325 case decl of
1444 case decl of
1326 DeclStart row col ->
1445 DeclStart row col ->
1327− case Code.whatIsNext source row col of
1446+ toDeclStartReport source row col
1328− Code.Close term bracket ->
1330− region = toRegion row col
1332− Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
1333− Code.toSnippet source region Nothing
1336− "I was not expecting to see a " ++ term ++ " here:"
1338− "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
1341− Code.Keyword keyword ->
1343− region = toKeywordRegion row col keyword
1345− Report.Report "RESERVED WORD" region [] $
1346− Code.toSnippet source region Nothing
1349− "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
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!"
1361− "It is reserved for writing `case` expressions. Try using a different name?"
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:"
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"]
1371− , D.indent 4 $ D.fillSep [D.blue "Nothing","->"]
1372− , D.indent 6 $ D.fillSep [D.dullyellow "400"]
1375− "This defines a `getWidth` function that we can use elsewhere in our program."
1381− "It is reserved for writing `if` expressions. Try using a different name?"
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:"
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\""
1394− "This defines a `reviewPowerLevel` function that we can use elsewhere in our program."
1399− "It is a reserved word. Try changing the name to something else?"
1404− region = toRegion row col
1406− Report.Report "SYNTAX PROBLEM" region [] $
1407− Code.toSnippet source region Nothing
1410− "I was expecting to see a declaration, but I am getting stuck here:"
1413− [ case Code.whatIsNext source row col of
1414− Code.Other (Just char) | Char.isUpper char ->
1416− "All declarations start with lower-case letters in Elm, so maybe this letter can\
1417− \ be changed to lower-case?"
1421− "Declarations normally start with a lower-case name or the `type` keyword."
1423− "Here are a couple valid declarations for reference:"
1425− [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
1426− , D.fillSep [D.green "add","x","y","="]
1427− , D.fillSep [" ","x","+","y"]
1429− , D.fillSep [D.cyan "type",D.green "User","=","Anonymous","|","LoggedIn String"]
1431− "Notice that these declarations start with lower-case letters. Capitalization\
1432− \ makes a difference in Elm!"
1436 DeclSpace space row col ->
1448 DeclSpace space row col ->
1437 toSpaceReport source space row col
1449 toSpaceReport source space row col
@@ -1461,6 +1473,165 @@ toDeclarationsReport source decl =
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 ->
1481+ region = toRegion row col
1483+ Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
1484+ Code.toSnippet source region Nothing
1487+ "I was not expecting to see a " ++ term ++ " here:"
1489+ "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
1492+ Code.Keyword keyword ->
1494+ region = toKeywordRegion row col keyword
1496+ Report.Report "RESERVED WORD" region [] $
1497+ Code.toSnippet source region Nothing
1500+ "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
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!"
1512+ "It is reserved for writing `case` expressions. Try using a different name?"
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"]
1522+ , D.indent 4 $ D.fillSep [D.blue "Nothing","->"]
1523+ , D.indent 6 $ D.fillSep [D.dullyellow "400"]
1526+ "This defines a `getWidth` function that you can use elsewhere in your program."
1532+ "It is reserved for writing `if` expressions. Try using a different name?"
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 $
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!\""
1546+ "This defines a `reviewPowerLevel` function that you can use elsewhere in your program."
1551+ "It is a reserved word. Try changing the name to something else?"
1556+ region = toRegion row col
1558+ Report.Report "UNEXPECTED CAPITAL LETTER" region [] $
1559+ Code.toSnippet source region Nothing
1562+ "Declarations always start with a lower-case letter, so I am getting stuck here:"
1566+ ["Try","a","name","like"
1567+ ,D.green (D.fromChars (Char.toLower c : cs))
1571+ "Here are a couple valid declarations for reference:"
1572+ , D.indent 4 $ D.vcat $
1573+ [ "greet : String -> String"
1575+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1577+ , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1580+ "Notice that they always start with a lower-case letter. Capitalization matters!"
1584+ Code.Other (Just char) | elem char ['(', '{', '[', '+', '-', '*', '/', '^', '&', '|', '"', '\'', '!', '@', '#', '$', '%'] ->
1586+ region = toRegion row col
1588+ Report.Report "UNEXPECTED SYMBOL" region [] $
1589+ Code.toSnippet source region Nothing
1592+ "I am getting stuck because this line starts with the " ++ [char] ++ " symbol:"
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"
1600+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1602+ , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1605+ "If this is not supposed to be a declaration, try adding some spaces before it?"
1611+ region = toRegion row col
1613+ Report.Report "WEIRD DECLARATION" region [] $
1614+ Code.toSnippet source region Nothing
1617+ "I am trying to parse a declaration, but I am getting stuck here:"
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"
1625+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1627+ , D.cyan "type" <> " User = Anonymous | LoggedIn String"
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?"
@@ -1587,7 +1758,7 @@ toPortReport source port_ startRow startCol =
1587 [ D.reflow $
1758 [ D.reflow $
1588 "I was expecting to see a type next. Here are examples of outgoing and\
1759 "I was expecting to see a type next. Here are examples of outgoing and\
1589 \ incoming ports for reference:"
1760 \ incoming ports for reference:"
1590− , D.vcat
1761+ , D.indent 4 $ D.vcat $
1591 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
1762 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
1592 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
1763 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
@@ -1606,7 +1777,7 @@ portNote =
1607 [ D.toSimpleNote $
1778 [ D.toSimpleNote $
1608 "Here are some example `port` declarations for reference:"
1779 "Here are some example `port` declarations for reference:"
1609− , D.vcat
1780+ , D.indent 4 $ D.vcat $
1610 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
1781 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
1611 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
1782 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
@@ -1789,8 +1960,8 @@ typeAliasNote =
1789 [ D.toSimpleNote $
1960 [ D.toSimpleNote $
1790 "Here is an example of a valid `type alias` for reference:"
1961 "Here is an example of a valid `type alias` for reference:"
1791 , D.vcat $
1962 , D.vcat $
1792− [ D.indent 0 $ D.fillSep [D.cyan "type",D.cyan "alias",D.green "Person","="]
1963+ [ D.indent 4 $ D.fillSep [D.cyan "type",D.cyan "alias","Person","="]
1793− , D.indent 2 $ D.vcat $
1964+ , D.indent 6 $ D.vcat $
1794 ["{ name : String"
1965 ["{ name : String"
1795 ,", age : Int"
1966 ,", age : Int"
1796 ,", height : Float"
1967 ,", height : Float"
@@ -1990,10 +2161,10 @@ customTypeNote =
1990 [ D.toSimpleNote $
2161 [ D.toSimpleNote $
1991 "Here is an example of a valid `type` declaration for reference:"
2162 "Here is an example of a valid `type` declaration for reference:"
1992 , D.vcat $
2163 , D.vcat $
1993− [ D.indent 0 $ D.fillSep [D.cyan "type",D.green "Status"]
2164+ [ D.indent 4 $ D.fillSep [D.cyan "type","Status"]
1994− , D.indent 2 $ D.fillSep ["=","Failure"]
2165+ , D.indent 6 $ D.fillSep ["=","Failure"]
1995− , D.indent 2 $ D.fillSep ["|","Waiting"]
2166+ , D.indent 6 $ D.fillSep ["|","Waiting"]
1996− , D.indent 2 $ D.fillSep ["|","Success","String"]
2167+ , D.indent 6 $ D.fillSep ["|","Success","String"]
1998 , D.reflow $
2169 , D.reflow $
1999 "This defines a new `Status` type with three variants. This could be useful if\
2170 "This defines a new `Status` type with three variants. This could be useful if\
@@ -2065,10 +2236,10 @@ toDeclDefReport source name declDef startRow startCol =
2065 ,"a","type","annotation.","It","could","be","something","else","though,","so"
2236 ,"a","type","annotation.","It","could","be","something","else","though,","so"
2066 ,"here","is","a","valid","definition","for","reference:"
2237 ,"here","is","a","valid","definition","for","reference:"
2068− , D.vcat
2239+ , D.indent 4 $ D.vcat $
2069− [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2240+ [ "greet : String -> String"
2070− , D.fillSep [D.green "add","x","y","="]
2241+ , "greet name ="
2071− , D.fillSep [" ","x","+","y"]
2242+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
2073 , D.reflow $
2244 , D.reflow $
2074 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
2245 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -2090,10 +2261,10 @@ toDeclDefReport source name declDef startRow startCol =
2090 [ D.reflow $
2261 [ D.reflow $
2091 "I am not sure what is going wrong exactly, so here is a valid\
2262 "I am not sure what is going wrong exactly, so here is a valid\
2092 \ definition (with an optional type annotation) for reference:"
2263 \ definition (with an optional type annotation) for reference:"
2093− , D.vcat
2264+ , D.indent 4 $ D.vcat $
2094− [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2265+ [ "greet : String -> String"
2095− , D.fillSep [D.green "add","x","y","="]
2266+ , "greet name ="
2096− , D.fillSep [" ","x","+","y"]
2267+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
2098 , D.reflow $
2269 , D.reflow $
2099 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
2270 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -2115,10 +2286,10 @@ toDeclDefReport source name declDef startRow startCol =
2115 [ D.reflow $
2286 [ D.reflow $
2116 "I am not sure what is going wrong exactly, so here is a valid\
2287 "I am not sure what is going wrong exactly, so here is a valid\
2117 \ definition (with an optional type annotation) for reference:"
2288 \ definition (with an optional type annotation) for reference:"
2118− , D.vcat
2289+ , D.indent 4 $ D.vcat $
2119− [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2290+ [ "greet : String -> String"
2120− , D.fillSep [D.green "add","x","y","="]
2291+ , "greet name ="
2121− , D.fillSep [" ","x","+","y"]
2292+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
2123 , D.reflow $
2294 , D.reflow $
2124 "Try to use that format!"
2295 "Try to use that format!"
@@ -2233,10 +2404,10 @@ declDefNote =
2234 [ D.reflow $
2405 [ D.reflow $
2235 "Here is a valid definition (with a type annotation) for reference:"
2406 "Here is a valid definition (with a type annotation) for reference:"
2236− , D.vcat
2407+ , D.indent 4 $ D.vcat $
2237− [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2408+ [ "greet : String -> String"
2238− , D.fillSep [D.green "add","x","y","="]
2409+ , "greet name ="
2239− , D.fillSep [" ","x","+","y"]
2410+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
2241 , D.reflow $
2412 , D.reflow $
2242 "The top line (called a \"type annotation\") is optional. You can leave it off\
2413 "The top line (called a \"type annotation\") is optional. You can leave it off\
@@ -2420,7 +2591,7 @@ toExprReport source context expr startRow startCol =
2420 ,"give","a","more","specific","hint!"
2591 ,"give","a","more","specific","hint!"
2422 , D.toSimpleNote $
2593 , D.toSimpleNote $
2423− "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.\
2424 \ Or if I run into operators in unexpected spots. Point is, there are a\
2595 \ Or if I run into operators in unexpected spots. Point is, there are a\
2425 \ couple ways I can get confused and give sort of weird advice!"
2596 \ couple ways I can get confused and give sort of weird advice!"
@@ -2569,17 +2740,15 @@ toStringReport source string row col =
2569 , D.toSimpleNote $
2740 , D.toSimpleNote $
2570 "For a string that spans multiple lines, you can use the multi-line string\
2741 "For a string that spans multiple lines, you can use the multi-line string\
2571 \ syntax like this:"
2742 \ syntax like this:"
2572− , D.vcat
2743+ , D.dullyellow $ D.indent 4 $ D.vcat $
2573− [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
2744+ [ "\"\"\""
2575− , D.dullyellow "# Multi-line Strings"
2745+ , "# Multi-line Strings"
2577− , D.dullyellow "- start with triple double quotes"
2747+ , "- start with triple double quotes"
2578− , D.dullyellow "- write whatever you want"
2748+ , "- write whatever you want"
2579− , D.dullyellow "- no need to escape newlines or double quotes"
2749+ , "- no need to escape newlines or double quotes"
2580− , D.dullyellow "- end with triple double quotes"
2750+ , "- end with triple double quotes"
2582− , D.dullyellow "\"\"\""
2751+ , "\"\"\""
@@ -2598,17 +2767,15 @@ toStringReport source string row col =
2598 [ D.reflow "Add a \"\"\" somewhere after this to end the string."
2767 [ D.reflow "Add a \"\"\" somewhere after this to end the string."
2599 , D.toSimpleNote $
2768 , D.toSimpleNote $
2600 "Here is a valid multi-line string for reference:"
2769 "Here is a valid multi-line string for reference:"
2601− , D.vcat
2770+ , D.dullyellow $ D.indent 4 $ D.vcat $
2602− [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
2771+ [ "\"\"\""
2604− , D.dullyellow "# Multi-line Strings"
2772+ , "# Multi-line Strings"
2606− , D.dullyellow "- start with triple double quotes"
2774+ , "- start with triple double quotes"
2607− , D.dullyellow "- write whatever you want"
2775+ , "- write whatever you want"
2608− , D.dullyellow "- no need to escape newlines or double quotes"
2776+ , "- no need to escape newlines or double quotes"
2609− , D.dullyellow "- end with triple double quotes"
2777+ , "- end with triple double quotes"
2611− , D.dullyellow "\"\"\""
2778+ , "\"\"\""
@@ -3073,8 +3240,8 @@ toUnfinishLetReport source row col startRow startCol message =
3073 [ message
3240 [ message
3074 , D.toSimpleNote $
3241 , D.toSimpleNote $
3075 "Here is an example with a valid `let` expression for reference:"
3242 "Here is an example with a valid `let` expression for reference:"
3076− , D.vcat $
3243+ , D.indent 4 $ D.vcat $
3077− [ D.indent 0 $ D.fillSep [D.green "viewPerson","person","="]
3244+ [ D.indent 0 $ D.fillSep ["viewPerson","person","="]
3078 , D.indent 2 $ D.fillSep [D.cyan "let"]
3245 , D.indent 2 $ D.fillSep [D.cyan "let"]
3079 , D.indent 4 $ D.fillSep ["fullName","="]
3246 , D.indent 4 $ D.fillSep ["fullName","="]
3080 , D.indent 6 $ D.fillSep ["person.firstName","++",D.dullyellow "\" \"","++","person.lastName"]
3247 , D.indent 6 $ D.fillSep ["person.firstName","++",D.dullyellow "\" \"","++","person.lastName"]
@@ -3192,10 +3359,10 @@ toLetDefReport source name def startRow startCol =
3192 ,"a","type","annotation.","It","could","be","something","else","though,","so"
3359 ,"a","type","annotation.","It","could","be","something","else","though,","so"
3193 ,"here","is","a","valid","definition","for","reference:"
3360 ,"here","is","a","valid","definition","for","reference:"
3195− , D.vcat
3362+ , D.indent 4 $ D.vcat $
3196− [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3363+ [ "greet : String -> String"
3197− , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3364+ , "greet name ="
3198− , D.indent 6 $ D.fillSep ["x","+","y"]
3365+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
3200 , D.reflow $
3367 , D.reflow $
3201 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
3368 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -3217,10 +3384,10 @@ toLetDefReport source name def startRow startCol =
3217 [ D.reflow $
3384 [ D.reflow $
3218 "I am not sure what is going wrong exactly, so here is a valid\
3385 "I am not sure what is going wrong exactly, so here is a valid\
3219 \ definition (with an optional type annotation) for reference:"
3386 \ definition (with an optional type annotation) for reference:"
3220− , D.vcat
3387+ , D.indent 4 $ D.vcat $
3221− [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3388+ [ "greet : String -> String"
3222− , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3389+ , "greet name ="
3223− , D.indent 6 $ D.fillSep ["x","+","y"]
3390+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
3225 , D.reflow $
3392 , D.reflow $
3226 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
3393 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -3242,10 +3409,10 @@ toLetDefReport source name def startRow startCol =
3242 [ D.reflow $
3409 [ D.reflow $
3243 "I am not sure what is going wrong exactly, so here is a valid\
3410 "I am not sure what is going wrong exactly, so here is a valid\
3244 \ definition (with an optional type annotation) for reference:"
3411 \ definition (with an optional type annotation) for reference:"
3245− , D.vcat
3412+ , D.indent 4 $ D.vcat $
3246− [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3413+ [ "greet : String -> String"
3247− , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3414+ , "greet name ="
3248− , D.indent 4 $ D.fillSep ["x","+","y"]
3415+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
3250 , D.reflow $
3417 , D.reflow $
3251 "Try to use that format!"
3418 "Try to use that format!"
@@ -3335,10 +3502,10 @@ defNote =
3336 [ D.reflow $
3503 [ D.reflow $
3337 "Here is a valid definition (with a type annotation) for reference:"
3504 "Here is a valid definition (with a type annotation) for reference:"
3338− , D.vcat
3505+ , D.indent 4 $ D.vcat $
3339− [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3506+ [ "greet : String -> String"
3340− , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3507+ , "greet name ="
3341− , D.indent 6 $ D.fillSep ["x","+","y"]
3508+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
3343 , D.reflow $
3510 , D.reflow $
3344 "The top line (called a \"type annotation\") is optional. You can leave it off\
3511 "The top line (called a \"type annotation\") is optional. You can leave it off\
@@ -3820,15 +3987,22 @@ toRecordReport source context record startRow startCol =
3820 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3987 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3821 region = toRegion row col
3988 region = toRegion row col
3823− Report.Report "UNFINISHED RECORD" region [] $
3990+ Report.Report "PROBLEM IN RECORD" region [] $
3824 Code.toSnippet source surroundings (Just region)
3991 Code.toSnippet source surroundings (Just region)
3826 D.reflow $
3993 D.reflow $
3827 "I just started parsing a record, but I got stuck here:"
3994 "I just started parsing a record, but I got stuck here:"
3829− D.fillSep
3997+ [ D.fillSep
3830− ["Records","look","like",D.dullyellow "{ x = 3, y = 4 },"
3831− ,"so","I","was","expecting","to","see","a","field","name","next."
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" <> "."
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
@@ -3837,7 +4011,7 @@ toRecordReport source context record startRow startCol =
3837 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4011 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3838 region = toRegion row col
4012 region = toRegion row col
3840− Report.Report "UNFINISHED RECORD" region [] $
4014+ Report.Report "PROBLEM IN RECORD" region [] $
3841 Code.toSnippet source surroundings (Just region)
4015 Code.toSnippet source surroundings (Just region)
3843 D.reflow $
4017 D.reflow $
@@ -3925,9 +4099,12 @@ toRecordReport source context record startRow startCol =
3926 [ D.fillSep
4100 [ D.fillSep
3927 ["I","was","expecting","to","see","another","record","field","defined","next,"
4101 ["I","was","expecting","to","see","another","record","field","defined","next,"
3928− ,"so","I","am","looking","for","a","lower-case","name","like"
4102+ ,"so","I","am","looking","for","a","name","like"
3929 ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
4103 ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
4106+ "Field names must start with a lower-case letter. After that, you can use\
4107+ \ any sequence of letters, numbers, and underscores."
3931 , noteForRecordError
4108 , noteForRecordError
@@ -3937,7 +4114,7 @@ toRecordReport source context record startRow startCol =
3937 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4114 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3938 region = toRegion row col
4115 region = toRegion row col
3940− Report.Report "UNFINISHED RECORD" region [] $
4117+ Report.Report "PROBLEM IN RECORD" region [] $
3941 Code.toSnippet source surroundings (Just region)
4118 Code.toSnippet source surroundings (Just region)
3943 D.reflow $
4120 D.reflow $
@@ -3969,29 +4146,54 @@ toRecordReport source context record startRow startCol =
3969 D.reflow $
4146 D.reflow $
3970 "I just saw the opening curly brace of a record, but then I got stuck here:"
4147 "I just saw the opening curly brace of a record, but then I got stuck here:"
3972− addNoteForRecordIndentError $
4149+ D.stack
3973− D.fillSep $
4150+ [ D.fillSep $
3974− ["I","am","expecting","a","record","like",D.dullyellow "{ x = 3, y = 4 }","here."
4151+ ["I","am","expecting","a","record","like",D.dullyellow "{ x = 3, y = 4 }","here."
3975− ,"Try","defining","some","fields","of","your","own?"
4152+ ,"Try","defining","some","fields","of","your","own?"
4154+ , noteForRecordIndentError
3979 RecordIndentEnd row col ->
4158 RecordIndentEnd row col ->
4159+ case Code.nextLineStartsWithCloseCurly source row of
4160+ Just (curlyRow, curlyCol) ->
4162+ surroundings = A.Region (A.Position startRow startCol) (A.Position curlyRow curlyCol)
4163+ region = toRegion curlyRow curlyCol
4165+ Report.Report "NEED MORE INDENTATION" region [] $
4166+ Code.toSnippet source surroundings (Just region)
4169+ "I was partway through parsing a record, but I got stuck here:"
4173+ "I need this curly brace to be indented more. Try adding some spaces before it!"
4174+ , noteForRecordError
3981− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4180+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3982− region = toRegion row col
4181+ region = toRegion row col
3984− Report.Report "UNFINISHED RECORD" region [] $
4183+ Report.Report "UNFINISHED RECORD" region [] $
3985− Code.toSnippet source surroundings (Just region)
4184+ Code.toSnippet source surroundings (Just region)
3987− D.reflow $
4186+ D.reflow $
4187+ "I was partway through parsing a record, but I got stuck here:"
3988− "I was expecting to see a closing curly brace next:"
4191+ ["I","was","expecting","to","see","a","closing","curly","brace","next."
3990− addNoteForRecordIndentError $
3992− ["Try","putting","an",D.green "}","and","see","if","that","helps?"
4192+ ,"Try","putting","a",D.green "}","next","and","see","if","that","helps?"
4194+ , noteForRecordIndentError
3996 RecordIndentField row col ->
4198 RecordIndentField row col ->
@@ -4025,10 +4227,12 @@ toRecordReport source context record startRow startCol =
4025 "I am partway through parsing a record. I just saw a record\
4227 "I am partway through parsing a record. I just saw a record\
4026 \ field, so I was expecting to see an equals sign next:"
4228 \ field, so I was expecting to see an equals sign next:"
4028− addNoteForRecordIndentError $
4230+ D.stack
4029− D.fillSep $
4231+ [ D.fillSep $
4030− ["Try","putting","an",D.green "=","followed","by","an","expression?"
4232+ ["Try","putting","an",D.green "=","followed","by","an","expression?"
4234+ , noteForRecordIndentError
4034 RecordIndentExpr row col ->
4238 RecordIndentExpr row col ->
@@ -4042,11 +4246,13 @@ toRecordReport source context record startRow startCol =
4042 D.reflow $
4246 D.reflow $
4043 "I am partway through parsing a record, and I was expecting to run into an expression next:"
4247 "I am partway through parsing a record, and I was expecting to run into an expression next:"
4045− addNoteForRecordIndentError $
4249+ D.stack
4046− D.fillSep $
4250+ [ D.fillSep $
4047− ["Try","putting","something","like"
4251+ ["Try","putting","something","like"
4048− ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
4252+ ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
4254+ , noteForRecordIndentError
@@ -4056,36 +4262,32 @@ noteForRecordError =
4056 [ D.toSimpleNote
4262 [ D.toSimpleNote
4057 "If you are trying to define a record across multiple lines, I recommend using this format:"
4263 "If you are trying to define a record across multiple lines, I recommend using this format:"
4058 , D.indent 4 $ D.vcat $
4264 , D.indent 4 $ D.vcat $
4059− [ "{ name = \"Alice\""
4265+ [ "{ name = " <> D.dullyellow "\"Alice\""
4060− , ", age = 42"
4266+ , ", age = " <> D.dullyellow "42"
4061− , ", height = 1.75"
4267+ , ", height = " <> D.dullyellow "1.75"
4064 , D.reflow $
4270 , D.reflow $
4065− "Notice that each line starts with some indentation. Usually two or four spaces. I\
4271+ "Notice that each line starts with some indentation. Usually two or four spaces.\
4066− \ know this style can be jarring for people coming from C-like syntax, but folks generally\
4272+ \ This is the stylistic convention in the Elm ecosystem."
4067− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4071−addNoteForRecordIndentError :: D.Doc -> D.Doc
4276+noteForRecordIndentError :: D.Doc
4072−addNoteForRecordIndentError normalRecommendation =
4277+noteForRecordIndentError =
4073− D.stack $
4278+ D.stack
4074− normalRecommendation
4076 [ D.toSimpleNote
4279 [ D.toSimpleNote
4077 "I may be confused by indentation. For example, if you are trying to define\
4280 "I may be confused by indentation. For example, if you are trying to define\
4078 \ a record across multiple lines, I recommend using this format:"
4281 \ a record across multiple lines, I recommend using this format:"
4079 , D.indent 4 $ D.vcat $
4282 , D.indent 4 $ D.vcat $
4080− [ "{ name = \"Alice\""
4283+ [ "{ name = " <> D.dullyellow "\"Alice\""
4081− , ", age = 42"
4284+ , ", age = " <> D.dullyellow "42"
4082− , ", height = 1.75"
4285+ , ", height = " <> D.dullyellow "1.75"
4085 , D.reflow $
4288 , D.reflow $
4086− "Notice that each line starts with some indentation. Usually two or four spaces. I\
4289+ "Notice that each line starts with some indentation. Usually two or four spaces.\
4087− \ know this style can be jarring for people coming from C-like syntax, but folks generally\
4290+ \ This is the stylistic convention in the Elm ecosystem!"
4088− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -4274,15 +4476,14 @@ toListReport source context list startRow startCol =
4274 , D.toSimpleNote
4476 , D.toSimpleNote
4275 "I recommend using the following format for lists that span multiple lines:"
4477 "I recommend using the following format for lists that span multiple lines:"
4276 , D.indent 4 $ D.vcat $
4478 , D.indent 4 $ D.vcat $
4277− [ "[ \"Alice\""
4479+ [ "[ " <> D.dullyellow "\"Alice\""
4278− , ", \"Bob\""
4480+ , ", " <> D.dullyellow "\"Bob\""
4279− , ", \"Chuck\""
4481+ , ", " <> D.dullyellow "\"Chuck\""
4282 , D.reflow $
4484 , D.reflow $
4283− "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4485+ "Notice that each line starts with some indentation. Usually two or four spaces.\
4284− \ This style can be jarring for people coming from C-like syntax, but folks generally\
4486+ \ This is the stylistic convention in the Elm ecosystem."
4285− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -4335,15 +4536,14 @@ toListReport source context list startRow startCol =
4335 "I may be confused by indentation. For example, if you are trying to define\
4536 "I may be confused by indentation. For example, if you are trying to define\
4336 \ a list across multiple lines, I recommend using this format:"
4537 \ a list across multiple lines, I recommend using this format:"
4337 , D.indent 4 $ D.vcat $
4538 , D.indent 4 $ D.vcat $
4338− [ "[ \"Alice\""
4539+ [ "[ " <> D.dullyellow "\"Alice\""
4339− , ", \"Bob\""
4540+ , ", " <> D.dullyellow "\"Bob\""
4340− , ", \"Chuck\""
4541+ , ", " <> D.dullyellow "\"Chuck\""
4343 , D.reflow $
4544 , D.reflow $
4344− "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4545+ "Notice that each line starts with some indentation. Usually two or four spaces.\
4345− \ This style can be jarring for people coming from C-like syntax, but folks generally\
4546+ \ This is the stylistic convention in the Elm ecosystem."
4346− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -4367,15 +4567,14 @@ toListReport source context list startRow startCol =
4367 "I may be confused by indentation. For example, if you are trying to define\
4567 "I may be confused by indentation. For example, if you are trying to define\
4368 \ a list across multiple lines, I recommend using this format:"
4568 \ a list across multiple lines, I recommend using this format:"
4369 , D.indent 4 $ D.vcat $
4569 , D.indent 4 $ D.vcat $
4370− [ "[ \"Alice\""
4570+ [ "[ " <> D.dullyellow "\"Alice\""
4371− , ", \"Bob\""
4571+ , ", " <> D.dullyellow "\"Bob\""
4372− , ", \"Chuck\""
4572+ , ", " <> D.dullyellow "\"Chuck\""
4375 , D.reflow $
4575 , D.reflow $
4376− "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4576+ "Notice that each line starts with some indentation. Usually two or four spaces.\
4377− \ This style can be jarring for people coming from C-like syntax, but folks generally\
4577+ \ This is the stylistic convention in the Elm ecosystem."
4378− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -4396,15 +4595,14 @@ toListReport source context list startRow startCol =
4396 , D.toSimpleNote
4595 , D.toSimpleNote
4397 "I recommend using the following format for lists that span multiple lines:"
4596 "I recommend using the following format for lists that span multiple lines:"
4398 , D.indent 4 $ D.vcat $
4597 , D.indent 4 $ D.vcat $
4399− [ "[ \"Alice\""
4598+ [ "[ " <> D.dullyellow "\"Alice\""
4400− , ", \"Bob\""
4599+ , ", " <> D.dullyellow "\"Bob\""
4401− , ", \"Chuck\""
4600+ , ", " <> D.dullyellow "\"Chuck\""
4404 , D.reflow $
4603 , D.reflow $
4405− "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4604+ "Notice that each line starts with some indentation. Usually two or four spaces.\
4406− \ This style can be jarring for people coming from C-like syntax, but folks generally\
4605+ \ This is the stylistic convention in the Elm ecosystem."
4407− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -5330,7 +5528,7 @@ toTRecordReport source context record startRow startCol =
5331 [ D.fillSep
5529 [ D.fillSep
5332 ["I","was","expecting","to","see","another","record","field","defined","next,"
5530 ["I","was","expecting","to","see","another","record","field","defined","next,"
5333− ,"so","I","am","looking","for","a","lower-case","name","like"
5531+ ,"so","I","am","looking","for","a","name","like"
5334 ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
5532 ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
5336 , noteForRecordTypeError
5534 , noteForRecordTypeError
@@ -5384,23 +5582,44 @@ toTRecordReport source context record startRow startCol =
5386 TRecordIndentEnd row col ->
5584 TRecordIndentEnd row col ->
5585+ case Code.nextLineStartsWithCloseCurly source row of
5586+ Just (curlyRow, curlyCol) ->
5388− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5588+ surroundings = A.Region (A.Position startRow startCol) (A.Position curlyRow curlyCol)
5389− region = toRegion row col
5589+ region = toRegion curlyRow curlyCol
5391− Report.Report "UNFINISHED RECORD TYPE" region [] $
5591+ Report.Report "NEED MORE INDENTATION" region [] $
5392− Code.toSnippet source surroundings (Just region)
5592+ Code.toSnippet source surroundings (Just region)
5394− D.reflow $
5594+ D.reflow $
5395− "I was expecting to see a closing curly brace next:"
5595+ "I was partway through parsing a record type, but I got stuck here:"
5397− D.stack
5597+ D.stack
5398− [ D.fillSep $
5598+ [ D.reflow $
5399− ["Try","putting","an",D.green "}","and","see","if","that","helps?"
5599+ "I need this curly brace to be indented more. Try adding some spaces before it!"
5600+ , noteForRecordTypeError
5606+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5607+ region = toRegion row col
5609+ Report.Report "UNFINISHED RECORD TYPE" region [] $
5610+ Code.toSnippet source surroundings (Just region)
5613+ "I was partway through parsing a record type, but I got stuck here:"
5617+ ["I","was","expecting","to","see","a","closing","curly","brace","next."
5618+ ,"Try","putting","a",D.green "}","next","and","see","if","that","helps?"
5401− , noteForRecordTypeIndentError
5620+ , noteForRecordTypeIndentError
5405 TRecordIndentField row col ->
5624 TRecordIndentField row col ->
@@ -5475,9 +5694,8 @@ noteForRecordTypeError =
5477 , D.reflow $
5696 , D.reflow $
5478− "Notice that each line starts with some indentation. Usually two or four spaces. I\
5697+ "Notice that each line starts with some indentation. Usually two or four spaces.\
5479− \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5698+ \ This is the stylistic convention in the Elm ecosystem."
5480− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -5494,9 +5712,8 @@ noteForRecordTypeIndentError =
5496 , D.reflow $
5714 , D.reflow $
5497− "Notice that each line starts with some indentation. Usually two or four spaces. I\
5715+ "Notice that each line starts with some indentation. Usually two or four spaces.\
5498− \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5716+ \ This is the stylistic convention in the Elm ecosystem."
5499− \ report that they are used to it (and often prefer it!) after a week or two of using Elm."