@@ -649,184 +649,9 @@ toParseErrorReport source modul =
649649 toSpaceReport source space row col
650650
651651 ModuleBadEnd 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− )
652+ if col == 1
653+ then toDeclStartReport source row col
654+ else toWeirdEndReport source row col
830655
831656 ModuleProblem row col ->
832657 let
@@ -1010,6 +835,7 @@ toParseErrorReport source modul =
1010835 ]
1011836 , D.reflow $
1012837 "Notice that the module names all start with capital letters. That is required!"
838+ , D.reflowLink "Read" "imports" "to learn more."
1013839 ]
1014840 )
1015841
@@ -1036,6 +862,7 @@ toParseErrorReport source modul =
1036862 ]
1037863 , D.reflow $
1038864 "Notice that the alias always starts with a capital letter. That is required!"
865+ , D.reflowLink "Read" "imports" "to learn more."
1039866 ]
1040867 )
1041868
@@ -1098,6 +925,192 @@ toParseErrorReport source modul =
1098925
1099926
1100927
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+
11011114-- IMPORTS
11021115
11031116
@@ -1123,6 +1136,7 @@ toImportReport source row col =
11231136 ]
11241137 , D.reflow $
11251138 "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."
11261140 ]
11271141 )
11281142
@@ -1429,189 +1443,194 @@ toDeclarationsReport :: Code.Source -> Decl -> Report.Report
14291443toDeclarationsReport source decl =
14301444 case decl of
14311445 DeclStart 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− )
1446+ toDeclStartReport source row col
14451447
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− ]
1448+ DeclSpace space row col ->
1449+ toSpaceReport source space row col
14821450
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− ]
1451+ Port port_ row col ->
1452+ toPortReport source port_ row col
15021453
1503− _ ->
1504− D.reflow $
1505− "It is a reserved word. Try changing the name to something else?"
1506− )
1454+ DeclType declType row col ->
1455+ toDeclTypeReport source declType row col
15071456
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− (
1515− D.reflow $
1516− "Declarations always start with a lower-case letter, so I am getting stuck here:"
1517− ,
1518− D.stack
1519− [ D.fillSep $
1520− ["Try","a","name","like"
1521− ,D.green (D.fromChars (Char.toLower c : cs))
1522− ,"instead?"
1523− ]
1524− , D.toSimpleNote $
1525− "Here are a couple valid declarations for reference:"
1526− , D.indent 4 $ D.vcat $
1527− [ "greet : String -> String"
1528− , "greet name ="
1529− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1530− , ""
1531− , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1532− ]
1533− , D.reflow $
1534− "Notice that they always start with a lower-case letter. Capitalization matters!"
1535− ]
1536− )
1457+ DeclDef name declDef row col ->
1458+ toDeclDefReport source name declDef row col
15371459
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− (
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+ )
1474+
1475+
1476+toDeclStartReport :: Code.Source -> Row -> Col -> Report.Report
1477+toDeclStartReport source row col =
1478+ case Code.whatIsNext source row col of
1479+ Code.Close term bracket ->
1480+ let
1481+ region = toRegion row col
1482+ in
1483+ Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
1484+ Code.toSnippet source region Nothing
1485+ (
1486+ D.reflow $
1487+ "I was not expecting to see a " ++ term ++ " here:"
1488+ , D.reflow $
1489+ "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
1490+ )
1491+
1492+ Code.Keyword keyword ->
1493+ let
1494+ region = toKeywordRegion row col keyword
1495+ in
1496+ Report.Report "RESERVED WORD" region [] $
1497+ Code.toSnippet source region Nothing
1498+ (
1499+ D.reflow $
1500+ "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
1501+ ,
1502+ case keyword of
1503+ "import" ->
15451504 D.reflow $
1546− "I am getting stuck because this line starts with the " ++ [char] ++ " symbol:"
1547− ,
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" ->
15481510 D.stack
15491511 [ D.reflow $
1550− "When a line has no spaces at the beginning, I expect it to be a declaration like one of these:"
1512+ "It is reserved for writing `case` expressions. Try using a different name?"
1513+ , D.toSimpleNote $
1514+ "If you are trying to write a `case` expression, it needs to be part of a\
1515+ \ definition. So you could write something like this instead:"
15511516 , D.indent 4 $ D.vcat $
1552− [ "greet : String -> String"
1553− , "greet name ="
1554− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
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"]
15551521 , ""
1556− , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1522+ , D.indent 4 $ D.fillSep [D.blue "Nothing","->"]
1523+ , D.indent 6 $ D.fillSep [D.dullyellow "400"]
15571524 ]
15581525 , D.reflow $
1559− "If this is not supposed to be a declaration, try adding some spaces before it?"
1526+ "This defines a `getWidth` function that you can use elsewhere in your program."
15601527 ]
1561− )
15621528
1563− _ ->
1564− let
1565− region = toRegion row col
1566− in
1567− Report.Report "WEIRD DECLARATION" region [] $
1568− Code.toSnippet source region Nothing
1569− (
1570− D.reflow $
1571− "I am trying to parse a declaration, but I am getting stuck here:"
1572− ,
1529+ "if" ->
15731530 D.stack
15741531 [ D.reflow $
1575− "I am not sure what is going wrong, so here are a couple valid declarations for reference:"
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:"
15761536 , 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"
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+ ]
15821544 ]
15831545 , D.reflow $
1584− "Try to make your declaration look like one of those?"
1546+ "This defines a `reviewPowerLevel` function that you can use elsewhere in your program."
15851547 ]
1586− )
1587−
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
15961548
1597− DeclDef name declDef row col ->
1598− toDeclDefReport source name declDef row col
1549+ _ ->
1550+ D.reflow $
1551+ "It is a reserved word. Try changing the name to something else?"
1552+ )
15991553
1600− DeclFreshLineAfterDocComment row col ->
1554+ Code.Upper c cs ->
16011555 let
16021556 region = toRegion row col
16031557 in
1604− Report.Report "EXPECTING DECLARATION" region [] $
1558+ Report.Report "UNEXPECTED CAPITAL LETTER" region [] $
16051559 Code.toSnippet source region Nothing
16061560 (
16071561 D.reflow $
1608− "I just saw a doc comment, but then I got stuck here:"
1562+ "Declarations always start with a lower-case letter, so I am getting stuck here:"
16091563 ,
1564+ D.stack
1565+ [ D.fillSep $
1566+ ["Try","a","name","like"
1567+ ,D.green (D.fromChars (Char.toLower c : cs))
1568+ ,"instead?"
1569+ ]
1570+ , D.toSimpleNote $
1571+ "Here are a couple valid declarations for reference:"
1572+ , D.indent 4 $ D.vcat $
1573+ [ "greet : String -> String"
1574+ , "greet name ="
1575+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1576+ , ""
1577+ , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1578+ ]
1579+ , D.reflow $
1580+ "Notice that they always start with a lower-case letter. Capitalization matters!"
1581+ ]
1582+ )
1583+
1584+ Code.Other (Just char) | elem char ['(', '{', '[', '+', '-', '*', '/', '^', '&', '|', '"', '\'', '!', '@', '#', '$', '%'] ->
1585+ let
1586+ region = toRegion row col
1587+ in
1588+ Report.Report "UNEXPECTED SYMBOL" region [] $
1589+ Code.toSnippet source region Nothing
1590+ (
16101591 D.reflow $
1611− "I was expecting to see the corresponding declaration next, starting on a fresh\
1612− \ line with no indentation."
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+ ]
16131607 )
16141608
1609+ _ ->
1610+ let
1611+ region = toRegion row col
1612+ in
1613+ Report.Report "WEIRD DECLARATION" region [] $
1614+ Code.toSnippet source region Nothing
1615+ (
1616+ D.reflow $
1617+ "I am trying to parse a declaration, but I am getting stuck here:"
1618+ ,
1619+ D.stack
1620+ [ D.reflow $
1621+ "When a line has no spaces at the beginning, I expect it to be a declaration like one of these:"
1622+ , D.indent 4 $ D.vcat $
1623+ [ "greet : String -> String"
1624+ , "greet name ="
1625+ , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1626+ , ""
1627+ , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1628+ ]
1629+ , D.reflow $
1630+ "Try to make your declaration look like one of those? Or if this is not\
1631+ \ supposed to be a declaration, try adding some spaces before it?"
1632+ ]
1633+ )
16151634
16161635
16171636-- PORT
@@ -2572,7 +2591,7 @@ toExprReport source context expr startRow startCol =
25722591 ,"give","a","more","specific","hint!"
25732592 ]
25742593 , D.toSimpleNote $
2575− "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
2594+ "This can also happen if I run into reserved words like `let` or `as` unexpectedly.\
25762595 \ Or if I run into operators in unexpected spots. Point is, there are a\
25772596 \ couple ways I can get confused and give sort of weird advice!"
25782597 ]