@@ -649,9 +649,184 @@ toParseErrorReport source modul =
649649 toSpaceReport source space row col
650650
651651 ModuleBadEnd row col ->
652− if col == 1
653− then toDeclStartReport source row col
654− else toWeirdEndReport source row col
652+ case Code.whatIsNext source row col of
653+ Code.Keyword keyword ->
654+ let
655+ region = toKeywordRegion row col keyword
656+ in
657+ Report.Report "RESERVED WORD" region [] $
658+ Code.toSnippet source region Nothing
659+ (
660+ D.reflow $
661+ "I got stuck on this reserved word:"
662+ ,
663+ D.reflow $
664+ "The name `" ++ keyword ++ "` is reserved, so try using a different name?"
665+ )
666+
667+ Code.Operator op ->
668+ let
669+ region = toKeywordRegion row col op
670+ in
671+ Report.Report "UNEXPECTED SYMBOL" region [] $
672+ Code.toSnippet source region Nothing
673+ (
674+ D.reflow $
675+ "I ran into an unexpected symbol:"
676+ ,
677+ D.reflow $
678+ "I was not expecting to see a " ++ op ++ " here. Try deleting it? Maybe\
679+ \ I can give a better hint from there?"
680+ )
681+
682+ Code.Close term bracket ->
683+ let
684+ region = toRegion row col
685+ in
686+ Report.Report ("UNEXPECTED " ++ map Char.toUpper term) region [] $
687+ Code.toSnippet source region Nothing
688+ (
689+ D.reflow $
690+ "I ran into an unexpected " ++ term ++ ":"
691+ ,
692+ D.reflow $
693+ "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
694+ )
695+
696+ Code.Lower c cs ->
697+ let
698+ region = toKeywordRegion row col (c:cs)
699+ in
700+ Report.Report "UNEXPECTED NAME" region [] $
701+ Code.toSnippet source region Nothing
702+ (
703+ D.reflow $
704+ "I got stuck on this name:"
705+ ,
706+ D.reflow $
707+ "It is confusing me a lot! Normally I can give fairly specific hints, but\
708+ \ something is really tripping me up this time."
709+ )
710+
711+ Code.Upper c cs ->
712+ let
713+ region = toKeywordRegion row col (c:cs)
714+ in
715+ Report.Report "UNEXPECTED NAME" region [] $
716+ Code.toSnippet source region Nothing
717+ (
718+ D.reflow $
719+ "I got stuck on this name:"
720+ ,
721+ D.reflow $
722+ "It is confusing me a lot! Normally I can give fairly specific hints, but\
723+ \ something is really tripping me up this time."
724+ )
725+
726+ Code.Other maybeChar ->
727+ let
728+ region = toRegion row col
729+ in
730+ case maybeChar of
731+ Just ';' ->
732+ Report.Report "UNEXPECTED SEMICOLON" region [] $
733+ Code.toSnippet source region Nothing
734+ (
735+ D.reflow $
736+ "I got stuck on this semicolon:"
737+ ,
738+ D.stack
739+ [ D.reflow $ "Try removing it?"
740+ , D.toSimpleNote $
741+ "Some languages require semicolons at the end of each statement. These are\
742+ \ often called C-like languages, and they usually share a lot of language design\
743+ \ choices. (E.g. side-effects, for loops, etc.) Elm manages effects with commands\
744+ \ and subscriptions instead, so there is no special syntax for \"statements\" and\
745+ \ therefore no need to use semicolons to separate them. I think this will make\
746+ \ more sense as you work through <https://guide.elm-lang.org> though!"
747+ ]
748+ )
749+
750+ Just ',' ->
751+ Report.Report "UNEXPECTED COMMA" region [] $
752+ Code.toSnippet source region Nothing
753+ (
754+ D.reflow $
755+ "I got stuck on this comma:"
756+ ,
757+ D.stack
758+ [ D.reflow $
759+ "I do not think I am parsing a list or tuple right now. Try deleting the comma?"
760+ , D.toSimpleNote $
761+ "If this is supposed to be part of a list, the problem may be a bit earlier.\
762+ \ Perhaps the opening [ is missing? Or perhaps some value in the list has an extra\
763+ \ closing ] that is making me think the list ended earlier? The same kinds of\
764+ \ things could be going wrong if this is supposed to be a tuple."
765+ ]
766+ )
767+
768+ Just '`' ->
769+ Report.Report "UNEXPECTED CHARACTER" region [] $
770+ Code.toSnippet source region Nothing
771+ (
772+ D.reflow $
773+ "I got stuck on this character:"
774+ ,
775+ D.stack
776+ [ D.reflow $
777+ "It is not used for anything in Elm syntax. It is used for multi-line strings in\
778+ \ some languages though, so if you want a string that spans multiple lines, you\
779+ \ can use Elm's multi-line string syntax like this:"
780+ , D.dullyellow $ D.indent 4 $ D.vcat $
781+ [ "\"\"\""
782+ , "# Multi-line Strings"
783+ , ""
784+ , "- start with triple double quotes"
785+ , "- write whatever you want"
786+ , "- no need to escape newlines or double quotes"
787+ , "- end with triple double quotes"
788+ , "\"\"\""
789+ ]
790+ , D.reflow $
791+ "Otherwise I do not know what is going on! Try removing the character?"
792+ ]
793+ )
794+
795+ Just '$' ->
796+ Report.Report "UNEXPECTED SYMBOL" region [] $
797+ Code.toSnippet source region Nothing
798+ (
799+ D.reflow $
800+ "I got stuck on this dollar sign:"
801+ ,
802+ D.reflow $
803+ "It is not used for anything in Elm syntax. Are you coming from a language where\
804+ \ dollar signs can be used in variable names? If so, try a name that (1) starts\
805+ \ with a letter and (2) only contains letters, numbers, and underscores."
806+ )
807+
808+ Just c | elem c ['#','@','!','%','~'] ->
809+ Report.Report "UNEXPECTED SYMBOL" region [] $
810+ Code.toSnippet source region Nothing
811+ (
812+ D.reflow $
813+ "I got stuck on this symbol:"
814+ ,
815+ D.reflow $
816+ "It is not used for anything in Elm syntax. Try removing it?"
817+ )
818+
819+ _ ->
820+ Report.Report "SYNTAX PROBLEM" region [] $
821+ Code.toSnippet source region Nothing
822+ (
823+ D.reflow $
824+ "I got stuck here:"
825+ ,
826+ D.reflow $
827+ "Whatever I am running into is confusing me a lot! Normally I can give fairly\
828+ \ specific hints, but something is really tripping me up this time."
829+ )
655830
656831 ModuleProblem row col ->
657832 let
@@ -835,7 +1010,6 @@ toParseErrorReport source modul =
8351010 ]
8361011 , D.reflow $
8371012 "Notice that the module names all start with capital letters. That is required!"
838− , D.reflowLink "Read" "imports" "to learn more."
8391013 ]
8401014 )
8411015
@@ -862,7 +1036,6 @@ toParseErrorReport source modul =
8621036 ]
8631037 , D.reflow $
8641038 "Notice that the alias always starts with a capital letter. That is required!"
865− , D.reflowLink "Read" "imports" "to learn more."
8661039 ]
8671040 )
8681041
@@ -925,192 +1098,6 @@ toParseErrorReport source modul =
9251098
9261099
9271100
928−-- WEIRD END
929−
930−
931−toWeirdEndReport :: Code.Source -> Row -> Col -> Report.Report
932−toWeirdEndReport source row col =
933− case Code.whatIsNext source row col of
934− Code.Keyword keyword ->
935− let
936− region = toKeywordRegion row col keyword
937− in
938− Report.Report "RESERVED WORD" region [] $
939− Code.toSnippet source region Nothing
940− (
941− D.reflow $
942− "I got stuck on this reserved word:"
943− ,
944− D.reflow $
945− "The name `" ++ keyword ++ "` is reserved, so try using a different name?"
946− )
947−
948− Code.Operator op ->
949− let
950− region = toKeywordRegion row col op
951− in
952− Report.Report "UNEXPECTED SYMBOL" region [] $
953− Code.toSnippet source region Nothing
954− (
955− D.reflow $
956− "I ran into an unexpected symbol:"
957− ,
958− D.reflow $
959− "I was not expecting to see a " ++ op ++ " here. Try deleting it? Maybe\
960− \ I can give a better hint from there?"
961− )
962−
963− Code.Close term bracket ->
964− let
965− region = toRegion row col
966− in
967− Report.Report ("UNEXPECTED " ++ map Char.toUpper term) region [] $
968− Code.toSnippet source region Nothing
969− (
970− D.reflow $
971− "I ran into an unexpected " ++ term ++ ":"
972− ,
973− D.reflow $
974− "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
975− )
976−
977− Code.Lower c cs ->
978− let
979− region = toKeywordRegion row col (c:cs)
980− in
981− Report.Report "UNEXPECTED NAME" region [] $
982− Code.toSnippet source region Nothing
983− (
984− D.reflow $
985− "I got stuck on this name:"
986− ,
987− D.reflow $
988− "It is confusing me a lot! Normally I can give fairly specific hints, but\
989− \ something is really tripping me up this time."
990− )
991−
992− Code.Upper c cs ->
993− let
994− region = toKeywordRegion row col (c:cs)
995− in
996− Report.Report "UNEXPECTED NAME" region [] $
997− Code.toSnippet source region Nothing
998− (
999− D.reflow $
1000− "I got stuck on this name:"
1001− ,
1002− D.reflow $
1003− "It is confusing me a lot! Normally I can give fairly specific hints, but\
1004− \ something is really tripping me up this time."
1005− )
1006−
1007− Code.Other maybeChar ->
1008− let
1009− region = toRegion row col
1010− in
1011− case maybeChar of
1012− Just ';' ->
1013− Report.Report "UNEXPECTED SEMICOLON" region [] $
1014− Code.toSnippet source region Nothing
1015− (
1016− D.reflow $
1017− "I got stuck on this semicolon:"
1018− ,
1019− D.stack
1020− [ D.reflow $ "Try removing it?"
1021− , D.toSimpleNote $
1022− "Some languages require semicolons at the end of each statement. These are\
1023− \ often called C-like languages, and they usually share a lot of language design\
1024− \ choices. (E.g. side-effects, for loops, etc.) Elm manages effects with commands\
1025− \ and subscriptions instead, so there is no special syntax for \"statements\" and\
1026− \ therefore no need to use semicolons to separate them. I think this will make\
1027− \ more sense as you work through <https://guide.elm-lang.org> though!"
1028− ]
1029− )
1030−
1031− Just ',' ->
1032− Report.Report "UNEXPECTED COMMA" region [] $
1033− Code.toSnippet source region Nothing
1034− (
1035− D.reflow $
1036− "I got stuck on this comma:"
1037− ,
1038− D.stack
1039− [ D.reflow $
1040− "I do not think I am parsing a list or tuple right now. Try deleting the comma?"
1041− , D.toSimpleNote $
1042− "If this is supposed to be part of a list, the problem may be a bit earlier.\
1043− \ Perhaps the opening [ is missing? Or perhaps some value in the list has an extra\
1044− \ closing ] that is making me think the list ended earlier? The same kinds of\
1045− \ things could be going wrong if this is supposed to be a tuple."
1046− ]
1047− )
1048−
1049− Just '`' ->
1050− Report.Report "UNEXPECTED CHARACTER" region [] $
1051− Code.toSnippet source region Nothing
1052− (
1053− D.reflow $
1054− "I got stuck on this character:"
1055− ,
1056− D.stack
1057− [ D.reflow $
1058− "It is not used for anything in Elm syntax. It is used for multi-line strings in\
1059− \ some languages though, so if you want a string that spans multiple lines, you\
1060− \ can use Elm's multi-line string syntax like this:"
1061− , D.dullyellow $ D.indent 4 $ D.vcat $
1062− [ "\"\"\""
1063− , "# Multi-line Strings"
1064− , ""
1065− , "- start with triple double quotes"
1066− , "- write whatever you want"
1067− , "- no need to escape newlines or double quotes"
1068− , "- end with triple double quotes"
1069− , "\"\"\""
1070− ]
1071− , D.reflow $
1072− "Otherwise I do not know what is going on! Try removing the character?"
1073− ]
1074− )
1075−
1076− Just '$' ->
1077− Report.Report "UNEXPECTED SYMBOL" region [] $
1078− Code.toSnippet source region Nothing
1079− (
1080− D.reflow $
1081− "I got stuck on this dollar sign:"
1082− ,
1083− D.reflow $
1084− "It is not used for anything in Elm syntax. Are you coming from a language where\
1085− \ dollar signs can be used in variable names? If so, try a name that (1) starts\
1086− \ with a letter and (2) only contains letters, numbers, and underscores."
1087− )
1088−
1089− Just c | elem c ['#','@','!','%','~'] ->
1090− Report.Report "UNEXPECTED SYMBOL" region [] $
1091− Code.toSnippet source region Nothing
1092− (
1093− D.reflow $
1094− "I got stuck on this symbol:"
1095− ,
1096− D.reflow $
1097− "It is not used for anything in Elm syntax. Try removing it?"
1098− )
1099−
1100− _ ->
1101− Report.Report "SYNTAX PROBLEM" region [] $
1102− Code.toSnippet source region Nothing
1103− (
1104− D.reflow $
1105− "I got stuck here:"
1106− ,
1107− D.reflow $
1108− "Whatever I am running into is confusing me a lot! Normally I can give fairly\
1109− \ specific hints, but something is really tripping me up this time."
1110− )
1111−
1112−
1113−
11141101-- IMPORTS
11151102
11161103
@@ -1136,7 +1123,6 @@ toImportReport source row col =
11361123 ]
11371124 , D.reflow $
11381125 "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."
11401126 ]
11411127 )
11421128
@@ -1443,196 +1429,191 @@ toDeclarationsReport :: Code.Source -> Decl -> Report.Report
14431429toDeclarationsReport source decl =
14441430 case decl of
14451431 DeclStart row col ->
1446− toDeclStartReport source row col
1447−
1448− DeclSpace space row col ->
1449− toSpaceReport source space row col
1450−
1451− Port port_ row col ->
1452− toPortReport source port_ row col
1453−
1454− DeclType declType row col ->
1455− toDeclTypeReport source declType row col
1456−
1457− DeclDef name declDef row col ->
1458− toDeclDefReport source name declDef row col
1432+ case Code.whatIsNext source row col of
1433+ Code.Close term bracket ->
1434+ let
1435+ region = toRegion row col
1436+ in
1437+ Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
1438+ Code.toSnippet source region Nothing
1439+ (
1440+ D.reflow $
1441+ "I was not expecting to see a " ++ term ++ " here:"
1442+ , D.reflow $
1443+ "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
1444+ )
14591445
1460− DeclFreshLineAfterDocComment row col ->
1461− let
1462− region = toRegion row col
1463− in
1464− Report.Report "EXPECTING DECLARATION" region [] $
1465− Code.toSnippet source region Nothing
1466− (
1467− D.reflow $
1468− "I just saw a doc comment, but then I got stuck here:"
1469− ,
1470− D.reflow $
1471− "I was expecting to see the corresponding declaration next, starting on a fresh\
1472− \ line with no indentation."
1473− )
1446+ Code.Keyword keyword ->
1447+ let
1448+ region = toKeywordRegion row col keyword
1449+ in
1450+ Report.Report "RESERVED WORD" region [] $
1451+ Code.toSnippet source region Nothing
1452+ (
1453+ D.reflow $
1454+ "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
1455+ ,
1456+ case keyword of
1457+ "import" ->
1458+ D.reflow $
1459+ "It is reserved for declaring imports at the top of your module. If you want\
1460+ \ another import, try moving it up top with the other imports. If you want to\
1461+ \ define a value or function, try changing the name to something else!"
1462+
1463+ "case" ->
1464+ D.stack
1465+ [ D.reflow $
1466+ "It is reserved for writing `case` expressions. Try using a different name?"
1467+ , D.toSimpleNote $
1468+ "If you are trying to write a `case` expression, it needs to be part of a\
1469+ \ definition. So you could write something like this instead:"
1470+ , D.indent 4 $ D.vcat $
1471+ [ D.indent 0 $ D.fillSep ["getWidth","maybeWidth","="]
1472+ , D.indent 2 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
1473+ , D.indent 4 $ D.fillSep [D.blue "Just","width","->"]
1474+ , D.indent 6 $ D.fillSep ["width","+",D.dullyellow "200"]
1475+ , ""
1476+ , D.indent 4 $ D.fillSep [D.blue "Nothing","->"]
1477+ , D.indent 6 $ D.fillSep [D.dullyellow "400"]
1478+ ]
1479+ , D.reflow $
1480+ "This defines a `getWidth` function that you can use elsewhere in your program."
1481+ ]
14741482
1483+ "if" ->
1484+ D.stack
1485+ [ D.reflow $
1486+ "It is reserved for writing `if` expressions. Try using a different name?"
1487+ , D.toSimpleNote $
1488+ "If you are trying to write an `if` expression, it needs to be part of a\
1489+ \ definition. So you could write something like this instead:"
1490+ , D.indent 4 $ D.vcat $
1491+ [ "greet name ="
1492+ , D.fillSep $
1493+ [" "
1494+ ,D.cyan "if","name","==",D.dullyellow "\"Abraham Lincoln\""
1495+ ,D.cyan "then",D.dullyellow "\"Greetings Mr. President.\""
1496+ ,D.cyan "else",D.dullyellow "\"Hey!\""
1497+ ]
1498+ ]
1499+ , D.reflow $
1500+ "This defines a `reviewPowerLevel` function that you can use elsewhere in your program."
1501+ ]
14751502
1476−toDeclStartReport :: Code.Source -> Row -> Col -> Report.Report
1477−toDeclStartReport source row col =
1478− case Code.whatIsNext source row col of
1479− Code.Close term bracket ->
1480− let
1481− region = toRegion row col
1482− in
1483− Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
1484− Code.toSnippet source region Nothing
1485− (
1486− D.reflow $
1487− "I was not expecting to see a " ++ term ++ " here:"
1488− , D.reflow $
1489− "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
1490− )
1503+ _ ->
1504+ D.reflow $
1505+ "It is a reserved word. Try changing the name to something else?"
1506+ )
14911507
1492− Code.Keyword keyword ->
1493− let
1494− region = toKeywordRegion row col keyword
1495− in
1496− Report.Report "RESERVED WORD" region [] $
1497− Code.toSnippet source region Nothing
1498− (
1499− D.reflow $
1500− "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
1501− ,
1502− case keyword of
1503− "import" ->
1508+ Code.Upper c cs ->
1509+ let
1510+ region = toRegion row col
1511+ in
1512+ Report.Report "UNEXPECTED CAPITAL LETTER" region [] $
1513+ Code.toSnippet source region Nothing
1514+ (
15041515 D.reflow $
1505− "It is reserved for declaring imports at the top of your module. If you want\
1506− \ another import, try moving it up top with the other imports. If you want to\
1507− \ define a value or function, try changing the name to something else!"
1508−
1509− "case" ->
1516+ "Declarations always start with a lower-case letter, so I am getting stuck here:"
1517+ ,
15101518 D.stack
1511− [ D.reflow $
1512− "It is reserved for writing `case` expressions. Try using a different name?"
1519+ [ D.fillSep $
1520+ ["Try","a","name","like"
1521+ ,D.green (D.fromChars (Char.toLower c : cs))
1522+ ,"instead?"
1523+ ]
15131524 , D.toSimpleNote $
1514− "If you are trying to write a `case` expression, it needs to be part of a\
1515− \ definition. So you could write something like this instead:"
1525+ "Here are a couple valid declarations for reference:"
15161526 , 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"]
1527+ [ "greet : String -> String"
1528+ , "greet name ="
1529+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
15211530 , ""
1522− , D.indent 4 $ D.fillSep [D.blue "Nothing","->"]
1523− , D.indent 6 $ D.fillSep [D.dullyellow "400"]
1531+ , D.cyan "type" <> " User = Anonymous | LoggedIn String"
15241532 ]
15251533 , D.reflow $
1526− "This defines a `getWidth` function that you can use elsewhere in your program."
1534+ "Notice that they always start with a lower-case letter. Capitalization matters!"
15271535 ]
1536+ )
15281537
1529− "if" ->
1538+ Code.Other (Just char) | elem char ['(', '{', '[', '+', '-', '*', '/', '^', '&', '|', '"', '\'', '!', '@', '#', '$', '%'] ->
1539+ let
1540+ region = toRegion row col
1541+ in
1542+ Report.Report "UNEXPECTED SYMBOL" region [] $
1543+ Code.toSnippet source region Nothing
1544+ (
1545+ D.reflow $
1546+ "I am getting stuck because this line starts with the " ++ [char] ++ " symbol:"
1547+ ,
15301548 D.stack
15311549 [ D.reflow $
1532− "It is reserved for writing `if` expressions. Try using a different name?"
1533− , D.toSimpleNote $
1534− "If you are trying to write an `if` expression, it needs to be part of a\
1535− \ definition. So you could write something like this instead:"
1550+ "When a line has no spaces at the beginning, I expect it to be a declaration like one of these:"
15361551 , D.indent 4 $ D.vcat $
1537− [ "greet name ="
1538− , D.fillSep $
1539− [" "
1540− ,D.cyan "if","name","==",D.dullyellow "\"Abraham Lincoln\""
1541− ,D.cyan "then",D.dullyellow "\"Greetings Mr. President.\""
1542− ,D.cyan "else",D.dullyellow "\"Hey!\""
1543− ]
1552+ [ "greet : String -> String"
1553+ , "greet name ="
1554+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1555+ , ""
1556+ , D.cyan "type" <> " User = Anonymous | LoggedIn String"
15441557 ]
15451558 , D.reflow $
1546− "This defines a `reviewPowerLevel` function that you can use elsewhere in your program."
1559+ "If this is not supposed to be a declaration, try adding some spaces before it?"
15471560 ]
1561+ )
15481562
1549− _ ->
1563+ _ ->
1564+ let
1565+ region = toRegion row col
1566+ in
1567+ Report.Report "WEIRD DECLARATION" region [] $
1568+ Code.toSnippet source region Nothing
1569+ (
15501570 D.reflow $
1551− "It is a reserved word. Try changing the name to something else?"
1552− )
1553−
1554− Code.Upper c cs ->
1555− let
1556− region = toRegion row col
1557− in
1558− Report.Report "UNEXPECTED CAPITAL LETTER" region [] $
1559− Code.toSnippet source region Nothing
1560− (
1561− D.reflow $
1562− "Declarations always start with a lower-case letter, so I am getting stuck here:"
1563− ,
1564− D.stack
1565− [ D.fillSep $
1566− ["Try","a","name","like"
1567− ,D.green (D.fromChars (Char.toLower c : cs))
1568− ,"instead?"
1569− ]
1570− , D.toSimpleNote $
1571− "Here are a couple valid declarations for reference:"
1572− , D.indent 4 $ D.vcat $
1573− [ "greet : String -> String"
1574− , "greet name ="
1575− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1576− , ""
1577− , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1571+ "I am trying to parse a declaration, but I am getting stuck here:"
1572+ ,
1573+ D.stack
1574+ [ D.reflow $
1575+ "I am not sure what is going wrong, so here are a couple valid declarations for reference:"
1576+ , D.indent 4 $ D.vcat $
1577+ [ "greet : String -> String"
1578+ , "greet name ="
1579+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1580+ , ""
1581+ , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1582+ ]
1583+ , D.reflow $
1584+ "Try to make your declaration look like one of those?"
15781585 ]
1579− , D.reflow $
1580− "Notice that they always start with a lower-case letter. Capitalization matters!"
1581− ]
1582− )
1586+ )
15831587
1584− Code.Other (Just char) | elem char ['(', '{', '[', '+', '-', '*', '/', '^', '&', '|', '"', '\'', '!', '@', '#', '$', '%'] ->
1585− let
1586− region = toRegion row col
1587− in
1588− Report.Report "UNEXPECTED SYMBOL" region [] $
1589− Code.toSnippet source region Nothing
1590− (
1591− D.reflow $
1592− "I am getting stuck because this line starts with the " ++ [char] ++ " symbol:"
1593− ,
1594− D.stack
1595− [ D.reflow $
1596− "When a line has no spaces at the beginning, I expect it to be a declaration like one of these:"
1597− , D.indent 4 $ D.vcat $
1598− [ "greet : String -> String"
1599− , "greet name ="
1600− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1601− , ""
1602− , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1603− ]
1604− , D.reflow $
1605− "If this is not supposed to be a declaration, try adding some spaces before it?"
1606− ]
1607− )
1588+ DeclSpace space row col ->
1589+ toSpaceReport source space row col
1590+
1591+ Port port_ row col ->
1592+ toPortReport source port_ row col
1593+
1594+ DeclType declType row col ->
1595+ toDeclTypeReport source declType row col
16081596
1609− _ ->
1597+ DeclDef name declDef row col ->
1598+ toDeclDefReport source name declDef row col
1599+
1600+ DeclFreshLineAfterDocComment row col ->
16101601 let
16111602 region = toRegion row col
16121603 in
1613− Report.Report "WEIRD DECLARATION" region [] $
1604+ Report.Report "EXPECTING DECLARATION" region [] $
16141605 Code.toSnippet source region Nothing
16151606 (
16161607 D.reflow $
1617− "I am trying to parse a declaration, but I am getting stuck here:"
1608+ "I just saw a doc comment, but then I got stuck here:"
16181609 ,
1619− D.stack
1620− [ D.reflow $
1621− "When a line has no spaces at the beginning, I expect it to be a declaration like one of these:"
1622− , D.indent 4 $ D.vcat $
1623− [ "greet : String -> String"
1624− , "greet name ="
1625− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1626− , ""
1627− , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1628− ]
1629− , D.reflow $
1630− "Try to make your declaration look like one of those? Or if this is not\
1631− \ supposed to be a declaration, try adding some spaces before it?"
1632− ]
1610+ D.reflow $
1611+ "I was expecting to see the corresponding declaration next, starting on a fresh\
1612+ \ line with no indentation."
16331613 )
16341614
16351615
1616+
16361617-- PORT
16371618
16381619
@@ -2591,7 +2572,7 @@ toExprReport source context expr startRow startCol =
25912572 ,"give","a","more","specific","hint!"
25922573 ]
25932574 , D.toSimpleNote $
2594− "This can also happen if I run into reserved words like `let` or `as` unexpectedly.\
2575+ "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
25952576 \ Or if I run into operators in unexpected spots. Point is, there are a\
25962577 \ couple ways I can get confused and give sort of weird advice!"
25972578 ]