@@ -2,7 +2,6 @@
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Error.Syntax
3module Reporting.Error.Syntax
4 ( Error(..)
4 ( Error(..)
7 , Module(..)
6 , Module(..)
8 , Exposing(..)
7 , Exposing(..)
@@ -40,7 +39,7 @@ module Reporting.Error.Syntax
40 , Number(..)
39 , Number(..)
42 , Space(..)
41 , Space(..)
43− , toSpaceReport
42+ , toReport
@@ -69,9 +68,6 @@ data Error
69 | ModuleNameMismatch ModuleName.Raw (A.Located ModuleName.Raw)
68 | ModuleNameMismatch ModuleName.Raw (A.Located ModuleName.Raw)
70 | UnexpectedPort A.Region
69 | UnexpectedPort A.Region
71 | NoPorts A.Region
70 | NoPorts A.Region
72− | NoPortsInPackage (A.Located Name.Name)
73− | NoPortModulesInPackage A.Region
74− | NoEffectsOutsideKernel A.Region
75 | ParseError Module
71 | ParseError Module
@@ -520,7 +516,7 @@ toReport source err =
522 [ D.reflow $
518 [ D.reflow $
523− "I need it to match the file path, so I was expecting to see `"
519+ "I need it to match the file path, so I was expecting it to see `"
524 ++ ModuleName.toChars expectedName
520 ++ ModuleName.toChars expectedName
525 ++ "` here. Make the following change, and you should be all set!"
521 ++ "` here. Make the following change, and you should be all set!"
526 , D.indent 4 $
522 , D.indent 4 $
@@ -564,84 +560,10 @@ 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."
619 ParseError modul ->
563 ParseError modul ->
620 toParseErrorReport source modul
564 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."
645toParseErrorReport :: Code.Source -> Module -> Report.Report
567toParseErrorReport :: Code.Source -> Module -> Report.Report
646toParseErrorReport source modul =
568toParseErrorReport source modul =
647 case modul of
569 case modul of
@@ -649,9 +571,64 @@ toParseErrorReport source modul =
649 toSpaceReport source space row col
571 toSpaceReport source space row col
651 ModuleBadEnd row col ->
573 ModuleBadEnd row col ->
652− if col == 1
574+ case Code.whatIsNext source row col of
653− then toDeclStartReport source row col
575+ Code.Keyword keyword ->
654− else toWeirdEndReport source row col
576+ let
577+ region = toKeywordRegion row col keyword
579+ Report.Report "RESERVED WORD" region [] $
580+ Code.toSnippet source region Nothing
583+ "I got stuck on this reserved word:"
586+ "The name `" ++ keyword ++ "` is reserved, so try using a different name?"
591+ region = toKeywordRegion row col op
593+ Report.Report "UNEXPECTED SYMBOL" region [] $
594+ Code.toSnippet source region Nothing
597+ "I ran into an unexpected symbol:"
600+ "I was not expecting to see a " ++ op ++ " here. Try deleting it? Maybe\
601+ \ I can give a better hint from there?"
604+ Code.Close term bracket ->
606+ region = toRegion row col
608+ Report.Report ("UNEXPECTED " ++ map Char.toUpper term) region [] $
609+ Code.toSnippet source region Nothing
612+ "I ran into an unexpected " ++ term ++ ":"
615+ "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
620+ region = toRegion row col
622+ Report.Report "SYNTAX PROBLEM" region [] $
623+ Code.toSnippet source region Nothing
629+ "Whatever I am running into is confusing me a lot! Normally I can give fairly\
630+ \ specific hints, but something is really tripping me up this time."
656 ModuleProblem row col ->
633 ModuleProblem row col ->
@@ -797,15 +774,15 @@ toParseErrorReport source modul =
797 [ D.reflow $
774 [ D.reflow $
798 "I am not sure what is going on, but I recommend starting an Elm\
775 "I am not sure what is going on, but I recommend starting an Elm\
799 \ file with the following lines:"
776 \ file with the following lines:"
800− , D.indent 4 $ D.vcat $
777+ , D.vcat
801 [ D.fillSep [D.cyan "import","Html"]
778 [ D.fillSep [D.cyan "import","Html"]
803− , "main ="
780+ , D.fillSep [D.green "main","="]
804− , " Html.text " <> D.dullyellow "\"Hello!\""
781+ , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
806 , D.reflow $
783 , D.reflow $
807− "You should be able to copy those lines directly into your file. Check out the\
784+ "You should be able to copy those lines directly into your file. Check out\
808− \ examples at <https://elm-lang.org/examples> for more help getting started!"
785+ \ some of the examples on https://elm-lang.org for more help getting started!"
809 , D.toSimpleNote $
786 , D.toSimpleNote $
810 "This can also happen when something is indented too much!"
787 "This can also happen when something is indented too much!"
@@ -830,12 +807,11 @@ toParseErrorReport source modul =
830 , D.indent 4 $ D.vcat $
807 , D.indent 4 $ D.vcat $
831 [ D.fillSep [D.cyan "import","Dict"]
808 [ D.fillSep [D.cyan "import","Dict"]
832 , D.fillSep [D.cyan "import","Maybe"]
809 , D.fillSep [D.cyan "import","Maybe"]
833− , D.fillSep [D.cyan "import","Html.Attributes",D.cyan "as","A"]
810+ , D.fillSep [D.cyan "import","Html.Attributes"]
834− , D.fillSep [D.cyan "import","Json.Decode",D.cyan "exposing","(..)"]
811+ , D.fillSep [D.cyan "import","Json.Decode"]
836 , D.reflow $
813 , D.reflow $
837 "Notice that the module names all start with capital letters. That is required!"
814 "Notice that the module names all start with capital letters. That is required!"
838− , D.reflowLink "Read" "imports" "to learn more."
@@ -846,7 +822,7 @@ toParseErrorReport source modul =
847 region = toRegion row col
823 region = toRegion row col
849− Report.Report "EXPECTING IMPORT ALIAS" region [] $
825+ Report.Report "EXECTING IMPORT ALIAS" region [] $
850 Code.toSnippet source region Nothing
826 Code.toSnippet source region Nothing
852 D.reflow $
828 D.reflow $
@@ -862,7 +838,6 @@ toParseErrorReport source modul =
863 , D.reflow $
839 , D.reflow $
864 "Notice that the alias always starts with a capital letter. That is required!"
840 "Notice that the alias always starts with a capital letter. That is required!"
865− , D.reflowLink "Read" "imports" "to learn more."
@@ -925,192 +900,6 @@ 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."
1114-- IMPORTS
903-- IMPORTS
@@ -1136,7 +925,6 @@ toImportReport source row col =
1137 , D.reflow $
926 , D.reflow $
1138 "You are probably trying to import a different module, but try to make it look like one of these examples!"
927 "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."
@@ -1443,7 +1231,106 @@ toDeclarationsReport :: Code.Source -> Decl -> Report.Report
1443toDeclarationsReport source decl =
1231toDeclarationsReport source decl =
1444 case decl of
1232 case decl of
1445 DeclStart row col ->
1233 DeclStart row col ->
1446− toDeclStartReport source row col
1234+ case Code.whatIsNext source row col of
1235+ Code.Close term bracket ->
1237+ region = toRegion row col
1239+ Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
1240+ Code.toSnippet source region Nothing
1243+ "I was not expecting to see a " ++ term ++ " here:"
1245+ "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
1248+ Code.Keyword keyword ->
1250+ region = toKeywordRegion row col keyword
1252+ Report.Report "RESERVED WORD" region [] $
1253+ Code.toSnippet source region Nothing
1256+ "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
1261+ "It is reserved for declaring imports at the top of your module. If you want\
1262+ \ another import, try moving it up top with the other imports. If you want to\
1263+ \ define a value or function, try changing the name to something else!"
1268+ "It is reserved for writing `case` expressions. Try using a different name?"
1270+ "If you are trying to write a `case` expression, it needs to be part of a\
1271+ \ definition. So you could write something like this instead:"
1273+ [ D.indent 0 $ D.fillSep [D.green "getWidth","maybeWidth","="]
1274+ , D.indent 2 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
1275+ , D.indent 4 $ D.fillSep [D.blue "Just","width","->"]
1276+ , D.indent 6 $ D.fillSep ["width","+",D.dullyellow "200"]
1278+ , D.indent 4 $ D.fillSep [D.blue "Nothing","->"]
1279+ , D.indent 6 $ D.fillSep [D.dullyellow "400"]
1282+ "This defines a `getWidth` function that we can use elsewhere in our program."
1288+ "It is reserved for writing `if` expressions. Try using a different name?"
1290+ "If you are trying to write an `if` expression, it needs to be part of a\
1291+ \ definition. So you could write something like this instead:"
1293+ [ D.indent 0 $ D.fillSep [D.green "reviewPowerLevel","powerLevel","="]
1294+ , D.indent 2 $ D.fillSep $
1295+ [D.cyan "if","powerLevel",">",D.dullyellow "9000"
1296+ ,D.cyan "then",D.dullyellow "\"OVER 9000!!!\""
1297+ ,D.cyan "else",D.dullyellow "\"not bad\""
1301+ "This defines a `reviewPowerLevel` function that we can use elsewhere in our program."
1306+ "It is a reserved word. Try changing the name to something else?"
1311+ region = toRegion row col
1313+ Report.Report "SYNTAX PROBLEM" region [] $
1314+ Code.toSnippet source region Nothing
1317+ "I was expecting to see a new declaration here:"
1321+ "I am not sure what is going wrong exactly, but here are a couple valid\
1322+ \ declarations for reference:"
1324+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
1325+ , D.fillSep [D.green "add","x","y","="]
1326+ , D.fillSep [" ","x","+","y"]
1328+ , D.fillSep [D.cyan "type",D.green "User","=","Anonymous","|","LoggedIn String"]
1330+ "Note that all declarations start with lower-case letters in Elm. Capitalization\
1331+ \ makes a difference, so be consious of that if you are working from examples!"
1448 DeclSpace space row col ->
1335 DeclSpace space row col ->
1449 toSpaceReport source space row col
1336 toSpaceReport source space row col
@@ -1473,165 +1360,6 @@ 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?"
@@ -1758,7 +1486,7 @@ toPortReport source port_ startRow startCol =
1758 [ D.reflow $
1486 [ D.reflow $
1759 "I was expecting to see a type next. Here are examples of outgoing and\
1487 "I was expecting to see a type next. Here are examples of outgoing and\
1760 \ incoming ports for reference:"
1488 \ incoming ports for reference:"
1761− , D.indent 4 $ D.vcat $
1489+ , D.vcat
1762 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
1490 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
1763 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
1491 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
@@ -1777,7 +1505,7 @@ portNote =
1778 [ D.toSimpleNote $
1506 [ D.toSimpleNote $
1779 "Here are some example `port` declarations for reference:"
1507 "Here are some example `port` declarations for reference:"
1780− , D.indent 4 $ D.vcat $
1508+ , D.vcat
1781 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
1509 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
1782 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
1510 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
@@ -1907,7 +1635,7 @@ toTypeAliasReport source typeAlias startRow startCol =
1909 [ D.reflow $
1637 [ D.reflow $
1910− "I was expecting to see a type variable or an equals sign next."
1638+ "I was expecting to see a type variable or an an equals sign next."
1911 , typeAliasNote
1639 , typeAliasNote
@@ -1928,7 +1656,7 @@ toTypeAliasReport source typeAlias startRow startCol =
1930 [ D.reflow $
1658 [ D.reflow $
1931− "I was expecting to see a type variable or an equals sign next."
1659+ "I was expecting to see a type variable or an an equals sign next."
1932 , typeAliasNote
1660 , typeAliasNote
@@ -1960,8 +1688,8 @@ typeAliasNote =
1960 [ D.toSimpleNote $
1688 [ D.toSimpleNote $
1961 "Here is an example of a valid `type alias` for reference:"
1689 "Here is an example of a valid `type alias` for reference:"
1962 , D.vcat $
1690 , D.vcat $
1963− [ D.indent 4 $ D.fillSep [D.cyan "type",D.cyan "alias","Person","="]
1691+ [ D.indent 0 $ D.fillSep [D.cyan "type",D.cyan "alias",D.green "Person","="]
1964− , D.indent 6 $ D.vcat $
1692+ , D.indent 2 $ D.vcat $
1965 ["{ name : String"
1693 ["{ name : String"
1966 ,", age : Int"
1694 ,", age : Int"
1967 ,", height : Float"
1695 ,", height : Float"
@@ -2035,7 +1763,7 @@ toCustomTypeReport source customType startRow startCol =
2037 [ D.reflow $
1765 [ D.reflow $
2038− "I was expecting to see a type variable or an equals sign next."
1766+ "I was expecting to see a type variable or an an equals sign next."
2039 , customTypeNote
1767 , customTypeNote
@@ -2095,7 +1823,7 @@ toCustomTypeReport source customType startRow startCol =
2097 [ D.reflow $
1825 [ D.reflow $
2098− "I was expecting to see a type variable or an equals sign next."
1826+ "I was expecting to see a type variable or an an equals sign next."
2099 , customTypeNote
1827 , customTypeNote
@@ -2161,10 +1889,10 @@ customTypeNote =
2161 [ D.toSimpleNote $
1889 [ D.toSimpleNote $
2162 "Here is an example of a valid `type` declaration for reference:"
1890 "Here is an example of a valid `type` declaration for reference:"
2163 , D.vcat $
1891 , D.vcat $
2164− [ D.indent 4 $ D.fillSep [D.cyan "type","Status"]
1892+ [ D.indent 0 $ D.fillSep [D.cyan "type",D.green "Status"]
2165− , D.indent 6 $ D.fillSep ["=","Failure"]
1893+ , D.indent 2 $ D.fillSep ["=","Failure"]
2166− , D.indent 6 $ D.fillSep ["|","Waiting"]
1894+ , D.indent 2 $ D.fillSep ["|","Waiting"]
2167− , D.indent 6 $ D.fillSep ["|","Success","String"]
1895+ , D.indent 2 $ D.fillSep ["|","Success","String"]
2169 , D.reflow $
1897 , D.reflow $
2170 "This defines a new `Status` type with three variants. This could be useful if\
1898 "This defines a new `Status` type with three variants. This could be useful if\
@@ -2193,57 +1921,13 @@ toDeclDefReport source name declDef startRow startCol =
2193 region = toKeywordRegion row col keyword
1921 region = toKeywordRegion row col keyword
2195 Report.Report "RESERVED WORD" region [] $
1923 Report.Report "RESERVED WORD" region [] $
2196− Code.toSnippet source surroundings (Just region)
2200− ,"`" <> D.cyan (D.fromChars keyword) <> "`"
2201− ,"is","reserved","in","Elm,","so","it","cannot"
2202− ,"be","used","as","an","argument","here:"
2207− "Try renaming it to something else."
2211− ["This","keyword","is","reserved","for","pattern","matches","like"
2212− ,"((x,y)",D.cyan "as","point)","where","you","want","to","name","a","tuple","and"
2213− ,"the","values","it","contains."
2218− "The `" ++ keyword ++ "` keyword has a special meaning in Elm, so it can only be used in certain situations."
2222− Code.Operator "->" ->
2224− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2225− region = toWiderRegion row col 2
2227− Report.Report "MISSING COLON?" region [] $
2228 Code.toSnippet source surroundings (Just region)
1924 Code.toSnippet source surroundings (Just region)
2230 D.reflow $
1926 D.reflow $
2231− "I was not expecting to see an arrow here:"
1927+ "It looks like you are trying to use `" ++ keyword ++ "` as an argument:"
2233− D.stack
1929+ D.reflow $
2234− [ D.fillSep
1930+ "This is a reserved word! Try using some other name?"
2235− ["This","usually","means","a",D.green ":","is","missing","a","bit","earlier","in"
2236− ,"a","type","annotation.","It","could","be","something","else","though,","so"
2237− ,"here","is","a","valid","definition","for","reference:"
2239− , D.indent 4 $ D.vcat $
2240− [ "greet : String -> String"
2242− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
2245− "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
2249 Code.Operator op ->
1933 Code.Operator op ->
@@ -2261,10 +1945,10 @@ toDeclDefReport source name declDef startRow startCol =
2261 [ D.reflow $
1945 [ D.reflow $
2262 "I am not sure what is going wrong exactly, so here is a valid\
1946 "I am not sure what is going wrong exactly, so here is a valid\
2263 \ definition (with an optional type annotation) for reference:"
1947 \ definition (with an optional type annotation) for reference:"
2264− , D.indent 4 $ D.vcat $
1948+ , D.vcat
2265− [ "greet : String -> String"
1949+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2266− , "greet name ="
1950+ , D.fillSep [D.green "add","x","y","="]
2267− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1951+ , D.fillSep [" ","x","+","y"]
2269 , D.reflow $
1953 , D.reflow $
2270 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
1954 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -2286,10 +1970,10 @@ toDeclDefReport source name declDef startRow startCol =
2286 [ D.reflow $
1970 [ D.reflow $
2287 "I am not sure what is going wrong exactly, so here is a valid\
1971 "I am not sure what is going wrong exactly, so here is a valid\
2288 \ definition (with an optional type annotation) for reference:"
1972 \ definition (with an optional type annotation) for reference:"
2289− , D.indent 4 $ D.vcat $
1973+ , D.vcat
2290− [ "greet : String -> String"
1974+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2291− , "greet name ="
1975+ , D.fillSep [D.green "add","x","y","="]
2292− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1976+ , D.fillSep [" ","x","+","y"]
2294 , D.reflow $
1978 , D.reflow $
2295 "Try to use that format!"
1979 "Try to use that format!"
@@ -2404,10 +2088,10 @@ declDefNote =
2405 [ D.reflow $
2089 [ D.reflow $
2406 "Here is a valid definition (with a type annotation) for reference:"
2090 "Here is a valid definition (with a type annotation) for reference:"
2407− , D.indent 4 $ D.vcat $
2091+ , D.vcat
2408− [ "greet : String -> String"
2092+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2409− , "greet name ="
2093+ , D.fillSep [D.green "add","x","y","="]
2410− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
2094+ , D.fillSep [" ","x","+","y"]
2412 , D.reflow $
2096 , D.reflow $
2413 "The top line (called a \"type annotation\") is optional. You can leave it off\
2097 "The top line (called a \"type annotation\") is optional. You can leave it off\
@@ -2519,40 +2203,25 @@ toExprReport source context expr startRow startCol =
2521 OperatorRight op row col ->
2205 OperatorRight op row col ->
2523− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2524− region = toRegion row col
2206+ let region = toRegion row col in
2525− isMath = elem op ["-","+","*","/","^"]
2527 Report.Report "MISSING EXPRESSION" region [] $
2207 Report.Report "MISSING EXPRESSION" region [] $
2528− Code.toSnippet source surroundings (Just region)
2208+ Code.toSnippet source region Nothing
2530 D.reflow $
2210 D.reflow $
2531− "I just saw a " ++ Name.toChars op ++ " "
2211+ "I was expecting to see an expression after this " ++ Name.toChars op ++ " operator:"
2532− ++ (if isMath then "sign" else "operator")
2533− ++ ", so I am getting stuck here:"
2535− if isMath then
2213+ D.stack
2536− D.fillSep
2214+ [ D.fillSep $
2537− ["I","was","expecting","to","see","an","expression","next."
2215+ ["You","can","just","put","anything","for","now,","like"
2538− ,"Something","like",D.dullyellow "42","or",D.dullyellow "1000"
2216+ ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
2539− ,"that","makes","sense","with","a",D.fromName op,"sign."
2217+ ,"Once","there","is","something","there,","I","can","probably"
2540− ]
2218+ ,"give","a","more","specific","hint!"
2541− else if op == "&&" || op == "||" then
2543− ["I","was","expecting","to","see","an","expression","next."
2544− ,"Something","like",D.dullyellow "True","or",D.dullyellow "False"
2545− ,"that","makes","sense","with","boolean","logic."
2547− else if op == "|>" then
2220+ , D.toSimpleNote $
2548− D.reflow $
2221+ "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
2549− "I was expecting to see a function next."
2222+ \ Or if I run into operators in unexpected spots. Point is, there are a\
2550− else if op == "<|" then
2223+ \ couple ways I can get confused and give sort of weird advice!"
2552− "I was expecting to see an argument next."
2555− "I was expecting to see an expression next."
2558 OperatorReserved operator row col ->
2227 OperatorReserved operator row col ->
@@ -2573,6 +2242,7 @@ toExprReport source context expr startRow startCol =
2573 InNode NElse r c _ -> (r, c, "an `if` expression")
2242 InNode NElse r c _ -> (r, c, "an `if` expression")
2574 InNode NCase r c _ -> (r, c, "a `case` expression")
2243 InNode NCase r c _ -> (r, c, "a `case` expression")
2575 InNode NBranch r c _ -> (r, c, "a `case` expression")
2244 InNode NBranch r c _ -> (r, c, "a `case` expression")
2245+ -- TODO check if this is actually the best way to get error messages here
2577 surroundings = A.Region (A.Position contextRow contextCol) (A.Position row col)
2247 surroundings = A.Region (A.Position contextRow contextCol) (A.Position row col)
2578 region = toRegion row col
2248 region = toRegion row col
@@ -2591,7 +2261,7 @@ toExprReport source context expr startRow startCol =
2591 ,"give","a","more","specific","hint!"
2261 ,"give","a","more","specific","hint!"
2593 , D.toSimpleNote $
2263 , D.toSimpleNote $
2594− "This can also happen if I run into reserved words like `let` or `as` unexpectedly.\
2264+ "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
2595 \ Or if I run into operators in unexpected spots. Point is, there are a\
2265 \ Or if I run into operators in unexpected spots. Point is, there are a\
2596 \ couple ways I can get confused and give sort of weird advice!"
2266 \ couple ways I can get confused and give sort of weird advice!"
@@ -2737,19 +2407,7 @@ toStringReport source string row col =
2737 ,"quotes","on","each","end.","Is","the","closing","double"
2407 ,"quotes","on","each","end.","Is","the","closing","double"
2738 ,"quote","missing","in","your","code?"
2408 ,"quote","missing","in","your","code?"
2741− "For a string that spans multiple lines, you can use the multi-line string\
2410+ , D.link "Note" "Read" "TODO" "if you want a string that spans multiple lines."
2742− \ syntax like this:"
2743− , D.dullyellow $ D.indent 4 $ D.vcat $
2745− , "# Multi-line Strings"
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"
@@ -2765,18 +2423,7 @@ toStringReport source string row col =
2767 [ D.reflow "Add a \"\"\" somewhere after this to end the string."
2425 [ D.reflow "Add a \"\"\" somewhere after this to end the string."
2768− , D.toSimpleNote $
2426+ , D.link "Hint" "Read" "TODO" "for more information on strings and multi-line strings."
2769− "Here is a valid multi-line string for reference:"
2770− , D.dullyellow $ D.indent 4 $ D.vcat $
2772− , "# Multi-line Strings"
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"
@@ -3009,41 +2656,33 @@ toOperatorReport source context operator row col =
3010 Report.Report "UNEXPECTED ARROW" region [] $
2657 Report.Report "UNEXPECTED ARROW" region [] $
3011 Code.toSnippet source region Nothing $
2658 Code.toSnippet source region Nothing $
3012− if isWithin NCase context then
3015− "I am parsing a `case` expression right now, but this arrow is confusing me:"
3018− [ D.reflow "Maybe the `of` keyword is missing on a previous line?"
3023− else if isWithin NBranch context then
2659+ if isWithin NBranch context then
3025 D.reflow $
2661 D.reflow $
3026− "I am parsing a `case` expression right now, but this arrow is confusing me:"
2662+ "I was not expecting to see an arrow here:"
3029− [ D.reflow $
2666+ D.reflow $
3030− "It makes sense to see arrows around here, so I suspect it is something earlier. Maybe this pattern is indented a bit farther than the previous patterns?"
2667+ "I think I am parsing a `case` expression right now, so it makes sense to\
3031− , noteForCaseIndentError
2668+ \ see arrows around here. This one is confusing me though!"
2671+ "I may be getting confused by the indentation. Every pattern in a `case` must be\
2672+ \ exactly aligned (with exactly the same amount of indentation) so maybe this arrow\
2673+ \ appears after the next `case` pattern (correctly!) but the pattern itself is\
2674+ \ indented too far?"
3037 D.reflow $
2680 D.reflow $
3038− "I was partway through parsing an expression when I got stuck on this arrow:"
2681+ "I was not expecting an arrow here:"
3040− D.stack
2683+ D.reflow $
3041− [ "Arrows should only appear in `case` expressions and anonymous functions.\n\
2684+ "Arrows should only appear in `case` expressions and anonymous functions. Maybe\
3042− \Maybe it was supposed to be a > sign instead?"
2685+ \ you want > or >= instead?"
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?"
3049 BadEquals ->
2688 BadEquals ->
@@ -3170,7 +2809,7 @@ toLetReport source context let_ startRow startCol =
3170 , D.toSimpleNote $
2809 , D.toSimpleNote $
3171 "This can also happen if you are trying to define another value within the `let` but\
2810 "This can also happen if you are trying to define another value within the `let` but\
3172 \ it is not indented enough. Make sure each definition has exactly the same amount of\
2811 \ it is not indented enough. Make sure each definition has exactly the same amount of\
3173− \ spaces before it. They should line up exactly!"
2812+ \ spaces before it. The should line up exactly!"
@@ -3240,8 +2879,8 @@ toUnfinishLetReport source row col startRow startCol message =
3240 [ message
2879 [ message
3241 , D.toSimpleNote $
2880 , D.toSimpleNote $
3242 "Here is an example with a valid `let` expression for reference:"
2881 "Here is an example with a valid `let` expression for reference:"
3243− , D.indent 4 $ D.vcat $
2882+ , D.vcat $
3244− [ D.indent 0 $ D.fillSep ["viewPerson","person","="]
2883+ [ D.indent 0 $ D.fillSep [D.green "viewPerson","person","="]
3245 , D.indent 2 $ D.fillSep [D.cyan "let"]
2884 , D.indent 2 $ D.fillSep [D.cyan "let"]
3246 , D.indent 4 $ D.fillSep ["fullName","="]
2885 , D.indent 4 $ D.fillSep ["fullName","="]
3247 , D.indent 6 $ D.fillSep ["person.firstName","++",D.dullyellow "\" \"","++","person.lastName"]
2886 , D.indent 6 $ D.fillSep ["person.firstName","++",D.dullyellow "\" \"","++","person.lastName"]
@@ -3316,57 +2955,13 @@ toLetDefReport source name def startRow startCol =
3316 region = toKeywordRegion row col keyword
2955 region = toKeywordRegion row col keyword
3318 Report.Report "RESERVED WORD" region [] $
2957 Report.Report "RESERVED WORD" region [] $
3319− Code.toSnippet source surroundings (Just region)
3323− ,"`" <> D.cyan (D.fromChars keyword) <> "`"
3324− ,"is","reserved","in","Elm,","so","it","cannot"
3325− ,"be","used","as","an","argument","here:"
3330− "Try renaming it to something else."
3334− ["This","keyword","is","reserved","for","pattern","matches","like"
3335− ,"((x,y)",D.cyan "as","point)","where","you","want","to","name","a","tuple","and"
3336− ,"the","values","it","contains."
3341− "The `" ++ keyword ++ "` keyword has a special meaning in Elm, so it can only be used in certain situations."
3345− Code.Operator "->" ->
3347− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3348− region = toWiderRegion row col 2
3350− Report.Report "MISSING COLON?" region [] $
3351 Code.toSnippet source surroundings (Just region)
2958 Code.toSnippet source surroundings (Just region)
3353 D.reflow $
2960 D.reflow $
3354− "I was not expecting to see an arrow here:"
2961+ "It looks like you are trying to use `" ++ keyword ++ "` as an argument:"
3356− D.stack
2963+ D.reflow $
3357− [ D.fillSep
2964+ "This is a reserved word! Try using some other name?"
3358− ["This","usually","means","a",D.green ":","is","missing","a","bit","earlier","in"
3359− ,"a","type","annotation.","It","could","be","something","else","though,","so"
3360− ,"here","is","a","valid","definition","for","reference:"
3362− , D.indent 4 $ D.vcat $
3363− [ "greet : String -> String"
3365− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
3368− "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
3372 Code.Operator op ->
2967 Code.Operator op ->
@@ -3384,10 +2979,10 @@ toLetDefReport source name def startRow startCol =
3384 [ D.reflow $
2979 [ D.reflow $
3385 "I am not sure what is going wrong exactly, so here is a valid\
2980 "I am not sure what is going wrong exactly, so here is a valid\
3386 \ definition (with an optional type annotation) for reference:"
2981 \ definition (with an optional type annotation) for reference:"
3387− , D.indent 4 $ D.vcat $
2982+ , D.vcat
3388− [ "greet : String -> String"
2983+ [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3389− , "greet name ="
2984+ , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3390− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
2985+ , D.indent 6 $ D.fillSep ["x","+","y"]
3392 , D.reflow $
2987 , D.reflow $
3393 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
2988 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
@@ -3409,10 +3004,10 @@ toLetDefReport source name def startRow startCol =
3409 [ D.reflow $
3004 [ D.reflow $
3410 "I am not sure what is going wrong exactly, so here is a valid\
3005 "I am not sure what is going wrong exactly, so here is a valid\
3411 \ definition (with an optional type annotation) for reference:"
3006 \ definition (with an optional type annotation) for reference:"
3412− , D.indent 4 $ D.vcat $
3007+ , D.vcat
3413− [ "greet : String -> String"
3008+ [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3414− , "greet name ="
3009+ , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3415− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
3010+ , D.indent 4 $ D.fillSep ["x","+","y"]
3417 , D.reflow $
3012 , D.reflow $
3418 "Try to use that format!"
3013 "Try to use that format!"
@@ -3502,10 +3097,10 @@ defNote =
3503 [ D.reflow $
3098 [ D.reflow $
3504 "Here is a valid definition (with a type annotation) for reference:"
3099 "Here is a valid definition (with a type annotation) for reference:"
3505− , D.indent 4 $ D.vcat $
3100+ , D.vcat
3506− [ "greet : String -> String"
3101+ [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3507− , "greet name ="
3102+ , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3508− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
3103+ , D.indent 6 $ D.fillSep ["x","+","y"]
3510 , D.reflow $
3105 , D.reflow $
3511 "The top line (called a \"type annotation\") is optional. You can leave it off\
3106 "The top line (called a \"type annotation\") is optional. You can leave it off\
@@ -3668,10 +3263,9 @@ toCaseReport source context case_ startRow startCol =
3668 D.reflow $
3263 D.reflow $
3669 "I am partway through parsing a `case` expression, but I got stuck here:"
3264 "I am partway through parsing a `case` expression, but I got stuck here:"
3671− D.stack
3266+ addNoteForCaseIndentError $
3672− [ D.reflow "I was expecting to see an arrow next."
3268+ "I was expecting to see an arrow next."
3673− , noteForCaseIndentError
3677 CaseExpr expr row col ->
3271 CaseExpr expr row col ->
@@ -3719,39 +3313,34 @@ toUnfinishCaseReport source row col startRow startCol message =
3720 Report.Report "UNFINISHED CASE" region [] $
3314 Report.Report "UNFINISHED CASE" region [] $
3721 Code.toSnippet source surroundings (Just region)
3315 Code.toSnippet source surroundings (Just region)
3723− D.reflow $
3317+ D.reflow $
3724− "I was partway through parsing a `case` expression, but I got stuck here:"
3318+ "I was partway through parsing a `case` expression, but I got stuck here:"
3726− D.stack
3320+ D.stack
3727− [ message
3321+ [ message
3733−noteForCaseError :: D.Doc
3736− [ D.toSimpleNote $
3322+ , D.toSimpleNote $
3737− "Here is an example of a valid `case` expression for reference."
3323+ "Here is an example of a valid `case` expression for reference."
3738− , D.vcat $
3324+ , D.vcat $
3739− [ D.indent 4 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
3325+ [ D.indent 4 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
3740− , D.indent 6 $ D.fillSep [D.blue "Just","width","->"]
3326+ , D.indent 6 $ D.fillSep [D.blue "Just","width","->"]
3741− , D.indent 8 $ D.fillSep ["width","+",D.dullyellow "200"]
3327+ , D.indent 8 $ D.fillSep ["width","+",D.dullyellow "200"]
3743− , D.indent 6 $ D.fillSep [D.blue "Nothing","->"]
3329+ , D.indent 6 $ D.fillSep [D.blue "Nothing","->"]
3744− , D.indent 8 $ D.fillSep [D.dullyellow "400"]
3330+ , D.indent 8 $ D.fillSep [D.dullyellow "400"]
3746− , D.reflow $
3332+ , D.reflow $
3747− "Notice the indentation. Each pattern is aligned, and each branch is indented\
3333+ "Notice the indentation. Each pattern is aligned, and each branch is indented\
3748− \ a bit more than the corresponding pattern. That is important!"
3334+ \ a bit more than the corresponding pattern. That is important!"
3752−noteForCaseIndentError :: D.Doc
3339+addNoteForCaseIndentError :: D.Doc -> D.Doc
3753−noteForCaseIndentError =
3340+addNoteForCaseIndentError message =
3754− D.stack
3341+ D.stack $
3755 [ D.toSimpleNote $
3344 [ D.toSimpleNote $
3756 "Sometimes I get confused by indentation, so try to make your `case` look\
3345 "Sometimes I get confused by indentation, so try to make your `case` look\
3757 \ something like this:"
3346 \ something like this:"
@@ -3764,9 +3353,8 @@ noteForCaseIndentError =
3764 , D.indent 8 $ D.fillSep [D.dullyellow "400"]
3353 , D.indent 8 $ D.fillSep [D.dullyellow "400"]
3766 , D.reflow $
3355 , D.reflow $
3767− "Notice the indentation! Patterns are aligned with each other. Same indentation.\
3356+ "Notice the indentation! Each pattern is aligned, and each branch is indented\
3768− \ The expressions after each arrow are all indented a bit more than the patterns.\
3769− \ That is important!"
3357+ \ a bit more than the corresponding pattern. That is important!"
@@ -3918,43 +3506,23 @@ toIfReport source context if_ startRow startCol =
3920 IfIndentElse row col ->
3508 IfIndentElse row col ->
3921− case Code.nextLineStartsWithKeyword "else" source row of
3922− Just (elseRow, elseCol) ->
3924− surroundings = A.Region (A.Position startRow startCol) (A.Position elseRow elseCol)
3925− region = toWiderRegion elseRow elseCol 4
3927− Report.Report "WEIRD ELSE BRANCH" region [] $
3928− Code.toSnippet source surroundings (Just region)
3931− "I was partway through an `if` expression when I got stuck here:"
3934− ["I","think","this",D.cyan "else","keyword","needs","to","be","indented","more."
3935− ,"Try","adding","some","spaces","before","it."
3941− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3510+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3942− region = toRegion row col
3511+ region = toRegion row col
3944− Report.Report "UNFINISHED IF" region [] $
3513+ Report.Report "UNFINISHED IF" region [] $
3945− Code.toSnippet source surroundings (Just region)
3514+ Code.toSnippet source surroundings (Just region)
3947− D.reflow $
3516+ D.reflow $
3948− "I was expecting to see an `else` branch after this:"
3517+ "I was expecting to see an `else` branch after this:"
3950− D.stack
3519+ D.stack
3951− [ D.fillSep
3520+ [ D.reflow $
3952− ["I","know","what","to","do","when","the","condition","is","True,"
3521+ "I know what to do when the condition is `True`, but not when it is `False`."
3953− ,"but","what","happens","when","it","is","False?"
3522+ , D.fillSep
3954− ,"Add","an",D.cyan "else","branch","to","handle","that","scenario!"
3523+ ["Add","an",D.cyan "else","branch","to","handle","that","scenario!"]
@@ -3987,22 +3555,15 @@ toRecordReport source context record startRow startCol =
3987 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3555 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3988 region = toRegion row col
3556 region = toRegion row col
3990− Report.Report "PROBLEM IN RECORD" region [] $
3558+ Report.Report "UNFINISHED RECORD" region [] $
3991 Code.toSnippet source surroundings (Just region)
3559 Code.toSnippet source surroundings (Just region)
3993 D.reflow $
3561 D.reflow $
3994 "I just started parsing a record, but I got stuck here:"
3562 "I just started parsing a record, but I got stuck here:"
3997− [ D.fillSep
3564+ D.fillSep
3565+ ["Records","look","like",D.dullyellow "{ x = 3, y = 4 },"
3998− ["I","was","expecting","to","see","a","record","field","defined","next,"
3566+ ,"so","I","was","expecting","to","see","a","field","name","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
@@ -4011,7 +3572,7 @@ toRecordReport source context record startRow startCol =
4011 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3572 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4012 region = toRegion row col
3573 region = toRegion row col
4014− Report.Report "PROBLEM IN RECORD" region [] $
3575+ Report.Report "UNFINISHED RECORD" region [] $
4015 Code.toSnippet source surroundings (Just region)
3576 Code.toSnippet source surroundings (Just region)
4017 D.reflow $
3578 D.reflow $
@@ -4046,67 +3607,22 @@ toRecordReport source context record startRow startCol =
4046 \ that is a reserved word. Try using a different name!"
3607 \ that is a reserved word. Try using a different name!"
4049− Code.Other (Just ',') ->
4051− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4052− region = toRegion row col
4054− Report.Report "EXTRA COMMA" region [] $
4055− Code.toSnippet source surroundings (Just region)
4058− "I am partway through parsing a record, but I got stuck here:"
4062− "I am seeing two commas in a row. This is the second one!"
4064− "Just delete one of the commas and you should be all set!"
4065− , noteForRecordError
4069− Code.Close _ '}' ->
4071− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4072− region = toRegion row col
4074− Report.Report "EXTRA COMMA" region [] $
4075− Code.toSnippet source surroundings (Just region)
4078− "I am partway through parsing a record, but I got stuck here:"
4082− "Trailing commas are not allowed in records. Try deleting the comma that appears\
4083− \ before this closing curly brace."
4084− , noteForRecordError
4090 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3612 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4091 region = toRegion row col
3613 region = toRegion row col
4093− Report.Report "PROBLEM IN RECORD" region [] $
3615+ Report.Report "UNFINISHED RECORD" region [] $
4094 Code.toSnippet source surroundings (Just region)
3616 Code.toSnippet source surroundings (Just region)
4096 D.reflow $
3618 D.reflow $
4097− "I am partway through parsing a record, but I got stuck here:"
3619+ "I am partway through parsing a record, but I got stuck after that last comma:"
4099− D.stack
3621+ addNoteForRecordError $
4100− [ D.fillSep
3622+ D.reflow $
4101− ["I","was","expecting","to","see","another","record","field","defined","next,"
3623+ "Trailing commas are not allowed in records, so I was expecting to see another\
4102− ,"so","I","am","looking","for","a","name","like"
3624+ \ record field defined next. If you are done defining the record, the fix may\
4103− ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
3625+ \ be to delete that last comma?"
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
4112 RecordEquals row col ->
3628 RecordEquals row col ->
@@ -4114,19 +3630,17 @@ toRecordReport source context record startRow startCol =
4114 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3630 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4115 region = toRegion row col
3631 region = toRegion row col
4117− Report.Report "PROBLEM IN RECORD" region [] $
3633+ Report.Report "UNFINISHED RECORD" region [] $
4118 Code.toSnippet source surroundings (Just region)
3634 Code.toSnippet source surroundings (Just region)
4120 D.reflow $
3636 D.reflow $
4121 "I am partway through parsing a record, but I got stuck here:"
3637 "I am partway through parsing a record, but I got stuck here:"
4123− D.stack
3639+ addNoteForRecordError $
4124− [ D.fillSep $
3640+ D.fillSep $
4125− ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
3641+ ["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?"
3642+ ,"an","equals","sign","next.","So","try","putting","an",D.green "=","sign","here?"
4128− , noteForRecordError
4132 RecordExpr expr row col ->
3646 RecordExpr expr row col ->
@@ -4146,54 +3660,29 @@ toRecordReport source context record startRow startCol =
4146 D.reflow $
3660 D.reflow $
4147 "I just saw the opening curly brace of a record, but then I got stuck here:"
3661 "I just saw the opening curly brace of a record, but then I got stuck here:"
4149− D.stack
3663+ addNoteForRecordIndentError $
4150− [ D.fillSep $
3664+ D.fillSep $
4151− ["I","am","expecting","a","record","like",D.dullyellow "{ x = 3, y = 4 }","here."
3665+ ["I","am","expecting","a","record","like",D.dullyellow "{ x = 3, y = 4 }","here."
4152− ,"Try","defining","some","fields","of","your","own?"
3666+ ,"Try","defining","some","fields","of","your","own?"
4154− , noteForRecordIndentError
4158 RecordIndentEnd row col ->
3670 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
4180− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3672+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4181− region = toRegion row col
3673+ region = toRegion row col
4183− Report.Report "UNFINISHED RECORD" region [] $
3675+ Report.Report "UNFINISHED RECORD" region [] $
4184− Code.toSnippet source surroundings (Just region)
3676+ Code.toSnippet source surroundings (Just region)
4186− D.reflow $
3678+ D.reflow $
4187− "I was partway through parsing a record, but I got stuck here:"
4191− ["I","was","expecting","to","see","a","closing","curly","brace","next."
3679+ "I was expecting to see a closing curly brace next:"
3681+ addNoteForRecordIndentError $
4192− ,"Try","putting","a",D.green "}","next","and","see","if","that","helps?"
3683+ ["Try","putting","an",D.green "}","and","see","if","that","helps?"
4194− , noteForRecordIndentError
4198 RecordIndentField row col ->
3687 RecordIndentField row col ->
@@ -4206,13 +3695,11 @@ toRecordReport source context record startRow startCol =
4206 D.reflow $
3695 D.reflow $
4207 "I am partway through parsing a record, but I got stuck after that last comma:"
3696 "I am partway through parsing a record, but I got stuck after that last comma:"
4209− D.stack
3698+ addNoteForRecordError $
4210− [ D.reflow $
3699+ D.reflow $
4211− "Trailing commas are not allowed in records, so the fix may be to\
3700+ "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\
3701+ \ delete that last comma? Or maybe you were in the middle of defining\
4213− \ an additional field?"
3702+ \ an additional field?"
4214− , noteForRecordError
4218 RecordIndentEquals row col ->
3705 RecordIndentEquals row col ->
@@ -4227,12 +3714,10 @@ toRecordReport source context record startRow startCol =
4227 "I am partway through parsing a record. I just saw a record\
3714 "I am partway through parsing a record. I just saw a record\
4228 \ field, so I was expecting to see an equals sign next:"
3715 \ field, so I was expecting to see an equals sign next:"
4230− D.stack
3717+ addNoteForRecordIndentError $
4231− [ D.fillSep $
3718+ D.fillSep $
4232− ["Try","putting","an",D.green "=","followed","by","an","expression?"
3719+ ["Try","putting","an",D.green "=","followed","by","an","expression?"
4234− , noteForRecordIndentError
4238 RecordIndentExpr row col ->
3723 RecordIndentExpr row col ->
@@ -4246,48 +3731,52 @@ toRecordReport source context record startRow startCol =
4246 D.reflow $
3731 D.reflow $
4247 "I am partway through parsing a record, and I was expecting to run into an expression next:"
3732 "I am partway through parsing a record, and I was expecting to run into an expression next:"
4249− D.stack
3734+ addNoteForRecordIndentError $
4250− [ D.fillSep $
3735+ D.fillSep $
4251− ["Try","putting","something","like"
3736+ ["Try","putting","something","like"
4252− ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
3737+ ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
4254− , noteForRecordIndentError
4259−noteForRecordError :: D.Doc
3742+addNoteForRecordError :: D.Doc -> D.Doc
4260−noteForRecordError =
3743+addNoteForRecordError normalRecommendation =
4261 D.stack $
3744 D.stack $
3745+ normalRecommendation
4262 [ D.toSimpleNote
3747 [ D.toSimpleNote
4263 "If you are trying to define a record across multiple lines, I recommend using this format:"
3748 "If you are trying to define a record across multiple lines, I recommend using this format:"
4264 , D.indent 4 $ D.vcat $
3749 , D.indent 4 $ D.vcat $
4265− [ "{ name = " <> D.dullyellow "\"Alice\""
3750+ [ "{ name = \"Alice\""
4266− , ", age = " <> D.dullyellow "42"
3751+ , ", age = 42"
4267− , ", height = " <> D.dullyellow "1.75"
3752+ , ", height = 1.75"
4270 , D.reflow $
3755 , D.reflow $
4271− "Notice that each line starts with some indentation. Usually two or four spaces.\
3756+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
4272− \ This is the stylistic convention in the Elm ecosystem."
3757+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
3758+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4276−noteForRecordIndentError :: D.Doc
3762+addNoteForRecordIndentError :: D.Doc -> D.Doc
4277−noteForRecordIndentError =
3763+addNoteForRecordIndentError normalRecommendation =
4278− D.stack
3764+ D.stack $
3765+ normalRecommendation
4279 [ D.toSimpleNote
3767 [ D.toSimpleNote
4280 "I may be confused by indentation. For example, if you are trying to define\
3768 "I may be confused by indentation. For example, if you are trying to define\
4281 \ a record across multiple lines, I recommend using this format:"
3769 \ a record across multiple lines, I recommend using this format:"
4282 , D.indent 4 $ D.vcat $
3770 , D.indent 4 $ D.vcat $
4283− [ "{ name = " <> D.dullyellow "\"Alice\""
3771+ [ "{ name = \"Alice\""
4284− , ", age = " <> D.dullyellow "42"
3772+ , ", age = 42"
4285− , ", height = " <> D.dullyellow "1.75"
3773+ , ", height = 1.75"
4288 , D.reflow $
3776 , D.reflow $
4289− "Notice that each line starts with some indentation. Usually two or four spaces.\
3777+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
4290− \ This is the stylistic convention in the Elm ecosystem!"
3778+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
3779+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -4476,14 +3965,15 @@ toListReport source context list startRow startCol =
4476 , D.toSimpleNote
3965 , D.toSimpleNote
4477 "I recommend using the following format for lists that span multiple lines:"
3966 "I recommend using the following format for lists that span multiple lines:"
4478 , D.indent 4 $ D.vcat $
3967 , D.indent 4 $ D.vcat $
4479− [ "[ " <> D.dullyellow "\"Alice\""
3968+ [ "[ \"Alice\""
4480− , ", " <> D.dullyellow "\"Bob\""
3969+ , ", \"Bob\""
4481− , ", " <> D.dullyellow "\"Chuck\""
3970+ , ", \"Chuck\""
4484 , D.reflow $
3973 , D.reflow $
4485− "Notice that each line starts with some indentation. Usually two or four spaces.\
3974+ "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4486− \ This is the stylistic convention in the Elm ecosystem."
3975+ \ This style can be jarring for people coming from C-like syntax, but folks generally\
3976+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -4536,14 +4026,15 @@ toListReport source context list startRow startCol =
4536 "I may be confused by indentation. For example, if you are trying to define\
4026 "I may be confused by indentation. For example, if you are trying to define\
4537 \ a list across multiple lines, I recommend using this format:"
4027 \ a list across multiple lines, I recommend using this format:"
4538 , D.indent 4 $ D.vcat $
4028 , D.indent 4 $ D.vcat $
4539− [ "[ " <> D.dullyellow "\"Alice\""
4029+ [ "[ \"Alice\""
4540− , ", " <> D.dullyellow "\"Bob\""
4030+ , ", \"Bob\""
4541− , ", " <> D.dullyellow "\"Chuck\""
4031+ , ", \"Chuck\""
4544 , D.reflow $
4034 , D.reflow $
4545− "Notice that each line starts with some indentation. Usually two or four spaces.\
4035+ "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4546− \ This is the stylistic convention in the Elm ecosystem."
4036+ \ This style can be jarring for people coming from C-like syntax, but folks generally\
4037+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -4567,14 +4058,15 @@ toListReport source context list startRow startCol =
4567 "I may be confused by indentation. For example, if you are trying to define\
4058 "I may be confused by indentation. For example, if you are trying to define\
4568 \ a list across multiple lines, I recommend using this format:"
4059 \ a list across multiple lines, I recommend using this format:"
4569 , D.indent 4 $ D.vcat $
4060 , D.indent 4 $ D.vcat $
4570− [ "[ " <> D.dullyellow "\"Alice\""
4061+ [ "[ \"Alice\""
4571− , ", " <> D.dullyellow "\"Bob\""
4062+ , ", \"Bob\""
4572− , ", " <> D.dullyellow "\"Chuck\""
4063+ , ", \"Chuck\""
4575 , D.reflow $
4066 , D.reflow $
4576− "Notice that each line starts with some indentation. Usually two or four spaces.\
4067+ "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4577− \ This is the stylistic convention in the Elm ecosystem."
4068+ \ This style can be jarring for people coming from C-like syntax, but folks generally\
4069+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -4595,14 +4087,15 @@ toListReport source context list startRow startCol =
4595 , D.toSimpleNote
4087 , D.toSimpleNote
4596 "I recommend using the following format for lists that span multiple lines:"
4088 "I recommend using the following format for lists that span multiple lines:"
4597 , D.indent 4 $ D.vcat $
4089 , D.indent 4 $ D.vcat $
4598− [ "[ " <> D.dullyellow "\"Alice\""
4090+ [ "[ \"Alice\""
4599− , ", " <> D.dullyellow "\"Bob\""
4091+ , ", \"Bob\""
4600− , ", " <> D.dullyellow "\"Chuck\""
4092+ , ", \"Chuck\""
4603 , D.reflow $
4095 , D.reflow $
4604− "Notice that each line starts with some indentation. Usually two or four spaces.\
4096+ "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4605− \ This is the stylistic convention in the Elm ecosystem."
4097+ \ This style can be jarring for people coming from C-like syntax, but folks generally\
4098+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -4851,7 +4344,7 @@ toPatternReport source context pattern startRow startCol =
4851 ,"((" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> ") " <> D.cyan "as" <> D.dullyellow " point" <> ")"
4344 ,"((" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> ") " <> D.cyan "as" <> D.dullyellow " point" <> ")"
4852 ,"so","you","can","refer","to","individual","parts","of","the","tuple","with"
4345 ,"so","you","can","refer","to","individual","parts","of","the","tuple","with"
4853 ,D.dullyellow "x","and",D.dullyellow "y","or","you","refer","to","the","whole"
4346 ,D.dullyellow "x","and",D.dullyellow "y","or","you","refer","to","the","whole"
4854− ,"thing","with",D.dullyellow "point" <> "."
4347+ ,"thing","with",D.dullyellow "point."
4856 , D.reflow $
4349 , D.reflow $
4857 "So I was expecting to see a variable name after the `as` keyword here. Sometimes\
4350 "So I was expecting to see a variable name after the `as` keyword here. Sometimes\
@@ -5043,7 +4536,7 @@ toPTupleReport source context tuple startRow startCol =
5043 "I just saw an open parenthesis, but I got stuck here:"
4536 "I just saw an open parenthesis, but I got stuck here:"
5045 D.fillSep
4538 D.fillSep
5046− ["I","was","expecting","to","see","a","pattern","next."
4539+ ["I","was","expecting","so","see","a","pattern","next."
5047 ,"Maybe","it","will","end","up","being","something"
4540 ,"Maybe","it","will","end","up","being","something"
5048 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "?"
4541 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "?"
@@ -5152,7 +4645,7 @@ toPTupleReport source context tuple startRow startCol =
5152 "I just saw an open parenthesis, but then I got stuck here:"
4645 "I just saw an open parenthesis, but then I got stuck here:"
5154 D.fillSep
4647 D.fillSep
5155− ["I","was","expecting","to","see","a","pattern","next."
4648+ ["I","was","expecting","so","see","a","pattern","next."
5156 ,"Maybe","it","will","end","up","being","something"
4649 ,"Maybe","it","will","end","up","being","something"
5157 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "?"
4650 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "?"
@@ -5171,7 +4664,7 @@ toPTupleReport source context tuple startRow startCol =
5173 [ D.fillSep
4666 [ D.fillSep
5174− ["I","was","expecting","to","see","a","pattern","next."
4667+ ["I","was","expecting","so","see","a","pattern","next."
5175 ,"I","am","expecting","the","final","result","to","be","something"
4668 ,"I","am","expecting","the","final","result","to","be","something"
5176 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "."
4669 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "."
@@ -5475,64 +4968,22 @@ toTRecordReport source context record startRow startCol =
5475 \ that is a reserved word. Try using a different name!"
4968 \ that is a reserved word. Try using a different name!"
5478− Code.Other (Just ',') ->
5480− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5481− region = toRegion row col
5483− Report.Report "EXTRA COMMA" region [] $
5484− Code.toSnippet source surroundings (Just region)
5487− "I am partway through parsing a record type, but I got stuck here:"
5491− "I am seeing two commas in a row. This is the second one!"
5493− "Just delete one of the commas and you should be all set!"
5494− , noteForRecordTypeError
5498− Code.Close _ '}' ->
5500− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5501− region = toRegion row col
5503− Report.Report "EXTRA COMMA" region [] $
5504− Code.toSnippet source surroundings (Just region)
5507− "I am partway through parsing a record type, but I got stuck here:"
5511− "Trailing commas are not allowed in record types. Try deleting the comma that\
5512− \ appears before this closing curly brace."
5513− , noteForRecordTypeError
5519 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4973 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5520 region = toRegion row col
4974 region = toRegion row col
5522− Report.Report "PROBLEM IN RECORD TYPE" region [] $
4976+ Report.Report "UNFINISHED RECORD TYPE" region [] $
5523 Code.toSnippet source surroundings (Just region)
4977 Code.toSnippet source surroundings (Just region)
5525 D.reflow $
4979 D.reflow $
5526− "I am partway through parsing a record type, but I got stuck here:"
4980+ "I am partway through parsing a record type, but I got stuck after that last comma:"
5528− D.stack
4982+ addNoteForRecordTypeError $
5529− [ D.fillSep
4983+ D.reflow $
5530− ["I","was","expecting","to","see","another","record","field","defined","next,"
4984+ "Trailing commas are not allowed in records, so I was expecting to see another\
5531− ,"so","I","am","looking","for","a","name","like"
4985+ \ record field defined next. If you are done defining the record, the fix may\
5532− ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
4986+ \ be to delete that last comma?"
5534− , noteForRecordTypeError
5538 TRecordColon row col ->
4989 TRecordColon row col ->
@@ -5546,13 +4997,11 @@ toTRecordReport source context record startRow startCol =
5546 D.reflow $
4997 D.reflow $
5547 "I am partway through parsing a record type, but I got stuck here:"
4998 "I am partway through parsing a record type, but I got stuck here:"
5549− D.stack
5000+ addNoteForRecordTypeError $
5550− [ D.fillSep $
5001+ D.fillSep $
5551− ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
5002+ ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
5552− ,"a","colon","next.","So","try","putting","an",D.green ":","sign","here?"
5003+ ,"a","colon","next.","So","try","putting","an",D.green ":","sign","here?"
5554− , noteForRecordTypeError
5558 TRecordType tipe row col ->
5007 TRecordType tipe row col ->
@@ -5572,54 +5021,29 @@ toTRecordReport source context record startRow startCol =
5572 D.reflow $
5021 D.reflow $
5573 "I just saw the opening curly brace of a record type, but then I got stuck here:"
5022 "I just saw the opening curly brace of a record type, but then I got stuck here:"
5575− D.stack
5024+ addNoteForRecordTypeIndentError $
5576− [ D.fillSep $
5025+ D.fillSep $
5577− ["I","am","expecting","a","record","like",D.dullyellow "{ name : String, age : Int }","here."
5026+ ["I","am","expecting","a","record","like",D.dullyellow "{ name : String, age : Int }","here."
5578− ,"Try","defining","some","fields","of","your","own?"
5027+ ,"Try","defining","some","fields","of","your","own?"
5580− , noteForRecordTypeIndentError
5584 TRecordIndentEnd row col ->
5031 TRecordIndentEnd row col ->
5585− case Code.nextLineStartsWithCloseCurly source row of
5586− Just (curlyRow, curlyCol) ->
5588− surroundings = A.Region (A.Position startRow startCol) (A.Position curlyRow curlyCol)
5589− region = toRegion curlyRow curlyCol
5591− Report.Report "NEED MORE INDENTATION" region [] $
5592− Code.toSnippet source surroundings (Just region)
5595− "I was partway through parsing a record type, but I got stuck here:"
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)
5033+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5607− region = toRegion row col
5034+ region = toRegion row col
5609− Report.Report "UNFINISHED RECORD TYPE" region [] $
5036+ Report.Report "UNFINISHED RECORD TYPE" region [] $
5610− Code.toSnippet source surroundings (Just region)
5037+ Code.toSnippet source surroundings (Just region)
5612− D.reflow $
5039+ D.reflow $
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."
5040+ "I was expecting to see a closing curly brace next:"
5042+ addNoteForRecordTypeIndentError $
5618− ,"Try","putting","a",D.green "}","next","and","see","if","that","helps?"
5044+ ["Try","putting","an",D.green "}","and","see","if","that","helps?"
5620− , noteForRecordTypeIndentError
5624 TRecordIndentField row col ->
5048 TRecordIndentField row col ->
@@ -5632,13 +5056,11 @@ toTRecordReport source context record startRow startCol =
5632 D.reflow $
5056 D.reflow $
5633 "I am partway through parsing a record type, but I got stuck after that last comma:"
5057 "I am partway through parsing a record type, but I got stuck after that last comma:"
5635− D.stack
5059+ addNoteForRecordTypeIndentError $
5636− [ D.reflow $
5060+ D.reflow $
5637− "Trailing commas are not allowed in record types, so the fix may be to\
5061+ "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\
5062+ \ delete that last comma? Or maybe you were in the middle of defining\
5639− \ an additional field?"
5063+ \ an additional field?"
5640− , noteForRecordTypeIndentError
5644 TRecordIndentColon row col ->
5066 TRecordIndentColon row col ->
@@ -5653,12 +5075,10 @@ toTRecordReport source context record startRow startCol =
5653 "I am partway through parsing a record type. I just saw a record\
5075 "I am partway through parsing a record type. I just saw a record\
5654 \ field, so I was expecting to see a colon next:"
5076 \ field, so I was expecting to see a colon next:"
5656− D.stack
5078+ addNoteForRecordTypeIndentError $
5657− [ D.fillSep $
5079+ D.fillSep $
5658− ["Try","putting","an",D.green ":","followed","by","a","type?"
5080+ ["Try","putting","an",D.green ":","followed","by","a","type?"
5660− , noteForRecordTypeIndentError
5664 TRecordIndentType row col ->
5084 TRecordIndentType row col ->
@@ -5672,19 +5092,19 @@ toTRecordReport source context record startRow startCol =
5672 D.reflow $
5092 D.reflow $
5673 "I am partway through parsing a record type, and I was expecting to run into a type next:"
5093 "I am partway through parsing a record type, and I was expecting to run into a type next:"
5675− D.stack
5095+ addNoteForRecordTypeIndentError $
5676− [ D.fillSep $
5096+ D.fillSep $
5677− ["Try","putting","something","like"
5097+ ["Try","putting","something","like"
5678− ,D.dullyellow "Int","or",D.dullyellow "String","for","now?"
5098+ ,D.dullyellow "Int","or",D.dullyellow "String","for","now?"
5680− , noteForRecordTypeIndentError
5685−noteForRecordTypeError :: D.Doc
5103+addNoteForRecordTypeError :: D.Doc -> D.Doc
5686−noteForRecordTypeError =
5104+addNoteForRecordTypeError normalRecommendation =
5687 D.stack $
5105 D.stack $
5106+ normalRecommendation
5688 [ D.toSimpleNote
5108 [ D.toSimpleNote
5689 "If you are trying to define a record type across multiple lines, I recommend using this format:"
5109 "If you are trying to define a record type across multiple lines, I recommend using this format:"
5690 , D.indent 4 $ D.vcat $
5110 , D.indent 4 $ D.vcat $
@@ -5694,14 +5114,17 @@ noteForRecordTypeError =
5696 , D.reflow $
5116 , D.reflow $
5697− "Notice that each line starts with some indentation. Usually two or four spaces.\
5117+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
5698− \ This is the stylistic convention in the Elm ecosystem."
5118+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5119+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
5702−noteForRecordTypeIndentError :: D.Doc
5123+addNoteForRecordTypeIndentError :: D.Doc -> D.Doc
5703−noteForRecordTypeIndentError =
5124+addNoteForRecordTypeIndentError normalRecommendation =
5704 D.stack $
5125 D.stack $
5126+ normalRecommendation
5705 [ D.toSimpleNote
5128 [ D.toSimpleNote
5706 "I may be confused by indentation. For example, if you are trying to define\
5129 "I may be confused by indentation. For example, if you are trying to define\
5707 \ a record type across multiple lines, I recommend using this format:"
5130 \ a record type across multiple lines, I recommend using this format:"
@@ -5712,8 +5135,9 @@ noteForRecordTypeIndentError =
5714 , D.reflow $
5137 , D.reflow $
5715− "Notice that each line starts with some indentation. Usually two or four spaces.\
5138+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
5716− \ This is the stylistic convention in the Elm ecosystem."
5139+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5140+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -5765,7 +5189,7 @@ toTTupleReport source context tuple startRow startCol =
5765 Code.toSnippet source surroundings (Just region)
5189 Code.toSnippet source surroundings (Just region)
5767 D.reflow $
5191 D.reflow $
5768− "I was expecting to see a closing parenthesis next, but I got stuck here:"
5192+ "I was expecting to see a closing parentheses next, but I got stuck here:"
5771 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
5195 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]