@@ -649,184 +649,9 @@ toParseErrorReport source modul =
649 toSpaceReport source space row col
649 toSpaceReport source space row col
651 ModuleBadEnd row col ->
651 ModuleBadEnd row col ->
652− case Code.whatIsNext source row col of
652+ if col == 1
653− Code.Keyword keyword ->
653+ then toDeclStartReport source row col
654− let
654+ else toWeirdEndReport source row col
655− region = toKeywordRegion row col keyword
657− Report.Report "RESERVED WORD" region [] $
658− Code.toSnippet source region Nothing
661− "I got stuck on this reserved word:"
664− "The name `" ++ keyword ++ "` is reserved, so try using a different name?"
669− region = toKeywordRegion row col op
671− Report.Report "UNEXPECTED SYMBOL" region [] $
672− Code.toSnippet source region Nothing
675− "I ran into an unexpected symbol:"
678− "I was not expecting to see a " ++ op ++ " here. Try deleting it? Maybe\
679− \ I can give a better hint from there?"
682− Code.Close term bracket ->
684− region = toRegion row col
686− Report.Report ("UNEXPECTED " ++ map Char.toUpper term) region [] $
687− Code.toSnippet source region Nothing
690− "I ran into an unexpected " ++ term ++ ":"
693− "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
698− region = toKeywordRegion row col (c:cs)
700− Report.Report "UNEXPECTED NAME" region [] $
701− Code.toSnippet source region Nothing
704− "I got stuck on this name:"
707− "It is confusing me a lot! Normally I can give fairly specific hints, but\
708− \ something is really tripping me up this time."
713− region = toKeywordRegion row col (c:cs)
715− Report.Report "UNEXPECTED NAME" region [] $
716− Code.toSnippet source region Nothing
719− "I got stuck on this name:"
722− "It is confusing me a lot! Normally I can give fairly specific hints, but\
723− \ something is really tripping me up this time."
726− Code.Other maybeChar ->
728− region = toRegion row col
732− Report.Report "UNEXPECTED SEMICOLON" region [] $
733− Code.toSnippet source region Nothing
736− "I got stuck on this semicolon:"
739− [ D.reflow $ "Try removing it?"
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!"
751− Report.Report "UNEXPECTED COMMA" region [] $
752− Code.toSnippet source region Nothing
755− "I got stuck on this comma:"
759− "I do not think I am parsing a list or tuple right now. Try deleting the comma?"
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."
769− Report.Report "UNEXPECTED CHARACTER" region [] $
770− Code.toSnippet source region Nothing
773− "I got stuck on this character:"
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 $
782− , "# Multi-line Strings"
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"
791− "Otherwise I do not know what is going on! Try removing the character?"
796− Report.Report "UNEXPECTED SYMBOL" region [] $
797− Code.toSnippet source region Nothing
800− "I got stuck on this dollar sign:"
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."
808− Just c | elem c ['#','@','!','%','~'] ->
809− Report.Report "UNEXPECTED SYMBOL" region [] $
810− Code.toSnippet source region Nothing
813− "I got stuck on this symbol:"
816− "It is not used for anything in Elm syntax. Try removing it?"
820− Report.Report "SYNTAX PROBLEM" region [] $
821− Code.toSnippet source region Nothing
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."
831 ModuleProblem row col ->
656 ModuleProblem row col ->
@@ -1100,6 +925,192 @@ toParseErrorReport source modul =
931+toWeirdEndReport :: Code.Source -> Row -> Col -> Report.Report
932+toWeirdEndReport source row col =
933+ case Code.whatIsNext source row col of
934+ Code.Keyword keyword ->
936+ region = toKeywordRegion row col keyword
938+ Report.Report "RESERVED WORD" region [] $
939+ Code.toSnippet source region Nothing
942+ "I got stuck on this reserved word:"
945+ "The name `" ++ keyword ++ "` is reserved, so try using a different name?"
950+ region = toKeywordRegion row col op
952+ Report.Report "UNEXPECTED SYMBOL" region [] $
953+ Code.toSnippet source region Nothing
956+ "I ran into an unexpected symbol:"
959+ "I was not expecting to see a " ++ op ++ " here. Try deleting it? Maybe\
960+ \ I can give a better hint from there?"
963+ Code.Close term bracket ->
965+ region = toRegion row col
967+ Report.Report ("UNEXPECTED " ++ map Char.toUpper term) region [] $
968+ Code.toSnippet source region Nothing
971+ "I ran into an unexpected " ++ term ++ ":"
974+ "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
979+ region = toKeywordRegion row col (c:cs)
981+ Report.Report "UNEXPECTED NAME" region [] $
982+ Code.toSnippet source region Nothing
985+ "I got stuck on this name:"
988+ "It is confusing me a lot! Normally I can give fairly specific hints, but\
989+ \ something is really tripping me up this time."
994+ region = toKeywordRegion row col (c:cs)
996+ Report.Report "UNEXPECTED NAME" region [] $
997+ Code.toSnippet source region Nothing
1000+ "I got stuck on this name:"
1003+ "It is confusing me a lot! Normally I can give fairly specific hints, but\
1004+ \ something is really tripping me up this time."
1007+ Code.Other maybeChar ->
1009+ region = toRegion row col
1013+ Report.Report "UNEXPECTED SEMICOLON" region [] $
1014+ Code.toSnippet source region Nothing
1017+ "I got stuck on this semicolon:"
1020+ [ D.reflow $ "Try removing it?"
1022+ "Some languages require semicolons at the end of each statement. These are\
1023+ \ often called C-like languages, and they usually share a lot of language design\
1024+ \ choices. (E.g. side-effects, for loops, etc.) Elm manages effects with commands\
1025+ \ and subscriptions instead, so there is no special syntax for \"statements\" and\
1026+ \ therefore no need to use semicolons to separate them. I think this will make\
1027+ \ more sense as you work through <https://guide.elm-lang.org> though!"
1032+ Report.Report "UNEXPECTED COMMA" region [] $
1033+ Code.toSnippet source region Nothing
1036+ "I got stuck on this comma:"
1040+ "I do not think I am parsing a list or tuple right now. Try deleting the comma?"
1042+ "If this is supposed to be part of a list, the problem may be a bit earlier.\
1043+ \ Perhaps the opening [ is missing? Or perhaps some value in the list has an extra\
1044+ \ closing ] that is making me think the list ended earlier? The same kinds of\
1045+ \ things could be going wrong if this is supposed to be a tuple."
1050+ Report.Report "UNEXPECTED CHARACTER" region [] $
1051+ Code.toSnippet source region Nothing
1054+ "I got stuck on this character:"
1058+ "It is not used for anything in Elm syntax. It is used for multi-line strings in\
1059+ \ some languages though, so if you want a string that spans multiple lines, you\
1060+ \ can use Elm's multi-line string syntax like this:"
1061+ , D.dullyellow $ D.indent 4 $ D.vcat $
1063+ , "# Multi-line Strings"
1065+ , "- start with triple double quotes"
1066+ , "- write whatever you want"
1067+ , "- no need to escape newlines or double quotes"
1068+ , "- end with triple double quotes"
1072+ "Otherwise I do not know what is going on! Try removing the character?"
1077+ Report.Report "UNEXPECTED SYMBOL" region [] $
1078+ Code.toSnippet source region Nothing
1081+ "I got stuck on this dollar sign:"
1084+ "It is not used for anything in Elm syntax. Are you coming from a language where\
1085+ \ dollar signs can be used in variable names? If so, try a name that (1) starts\
1086+ \ with a letter and (2) only contains letters, numbers, and underscores."
1089+ Just c | elem c ['#','@','!','%','~'] ->
1090+ Report.Report "UNEXPECTED SYMBOL" region [] $
1091+ Code.toSnippet source region Nothing
1094+ "I got stuck on this symbol:"
1097+ "It is not used for anything in Elm syntax. Try removing it?"
1101+ Report.Report "SYNTAX PROBLEM" region [] $
1102+ Code.toSnippet source region Nothing
1105+ "I got stuck here:"
1108+ "Whatever I am running into is confusing me a lot! Normally I can give fairly\
1109+ \ specific hints, but something is really tripping me up this time."
1103-- IMPORTS
1114-- IMPORTS
@@ -1432,189 +1443,194 @@ toDeclarationsReport :: Code.Source -> Decl -> Report.Report
1432toDeclarationsReport source decl =
1443toDeclarationsReport source decl =
1433 case decl of
1444 case decl of
1434 DeclStart row col ->
1445 DeclStart row col ->
1435− case Code.whatIsNext source row col of
1446+ toDeclStartReport source row col
1436− Code.Close term bracket ->
1438− region = toRegion row col
1440− Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
1441− Code.toSnippet source region Nothing
1444− "I was not expecting to see a " ++ term ++ " here:"
1446− "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
1449− Code.Keyword keyword ->
1448+ DeclSpace space row col ->
1450− let
1449+ toSpaceReport source space row col
1451− region = toKeywordRegion row col keyword
1453− Report.Report "RESERVED WORD" region [] $
1454− Code.toSnippet source region Nothing
1457− "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
1462− "It is reserved for declaring imports at the top of your module. If you want\
1463− \ another import, try moving it up top with the other imports. If you want to\
1464− \ define a value or function, try changing the name to something else!"
1469− "It is reserved for writing `case` expressions. Try using a different name?"
1471− "If you are trying to write a `case` expression, it needs to be part of a\
1472− \ definition. So you could write something like this instead:"
1473− , D.indent 4 $ D.vcat $
1474− [ D.indent 0 $ D.fillSep ["getWidth","maybeWidth","="]
1475− , D.indent 2 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
1476− , D.indent 4 $ D.fillSep [D.blue "Just","width","->"]
1477− , D.indent 6 $ D.fillSep ["width","+",D.dullyellow "200"]
1479− , D.indent 4 $ D.fillSep [D.blue "Nothing","->"]
1480− , D.indent 6 $ D.fillSep [D.dullyellow "400"]
1483− "This defines a `getWidth` function that you can use elsewhere in your program."
1486− "if" ->
1451+ Port port_ row col ->
1487− D.stack
1452+ toPortReport source port_ row col
1489− "It is reserved for writing `if` expressions. Try using a different name?"
1491− "If you are trying to write an `if` expression, it needs to be part of a\
1492− \ definition. So you could write something like this instead:"
1493− , D.indent 4 $ D.vcat $
1497− ,D.cyan "if","name","==",D.dullyellow "\"Abraham Lincoln\""
1498− ,D.cyan "then",D.dullyellow "\"Greetings Mr. President.\""
1499− ,D.cyan "else",D.dullyellow "\"Hey!\""
1503− "This defines a `reviewPowerLevel` function that you can use elsewhere in your program."
1506− _ ->
1454+ DeclType declType row col ->
1507− D.reflow $
1455+ toDeclTypeReport source declType row col
1508− "It is a reserved word. Try changing the name to something else?"
1511− Code.Upper c cs ->
1457+ DeclDef name declDef row col ->
1512− let
1458+ toDeclDefReport source name declDef row col
1513− region = toRegion row col
1515− Report.Report "UNEXPECTED CAPITAL LETTER" region [] $
1516− Code.toSnippet source region Nothing
1519− "Declarations always start with a lower-case letter, so I am getting stuck here:"
1523− ["Try","a","name","like"
1524− ,D.green (D.fromChars (Char.toLower c : cs))
1528− "Here are a couple valid declarations for reference:"
1529− , D.indent 4 $ D.vcat $
1530− [ "greet : String -> String"
1532− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1534− , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1537− "Notice that they always start with a lower-case letter. Capitalization matters!"
1541− Code.Other (Just char) | elem char ['(', '{', '[', '+', '-', '*', '/', '^', '&', '|', '"', '\'', '!', '@', '#', '$', '%'] ->
1460+ DeclFreshLineAfterDocComment row col ->
1462+ region = toRegion row col
1464+ Report.Report "EXPECTING DECLARATION" region [] $
1465+ Code.toSnippet source region Nothing
1468+ "I just saw a doc comment, but then I got stuck here:"
1471+ "I was expecting to see the corresponding declaration next, starting on a fresh\
1472+ \ line with no indentation."
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 ->
1543− region = toRegion row col
1494+ region = toKeywordRegion row col keyword
1545− Report.Report "UNEXPECTED SYMBOL" region [] $
1496+ Report.Report "RESERVED WORD" region [] $
1546− Code.toSnippet source region Nothing
1497+ Code.toSnippet source region Nothing
1500+ "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
1548 D.reflow $
1504 D.reflow $
1549− "I am getting stuck because this line starts with the " ++ [char] ++ " symbol:"
1505+ "It is reserved for declaring imports at the top of your module. If you want\
1550− ,
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!"
1552 [ D.reflow $
1511 [ D.reflow $
1553− "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?"
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:"
1554 , D.indent 4 $ D.vcat $
1516 , D.indent 4 $ D.vcat $
1555− [ "greet : String -> String"
1517+ [ D.indent 0 $ D.fillSep ["getWidth","maybeWidth","="]
1556− , "greet name ="
1518+ , D.indent 2 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
1557− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1519+ , D.indent 4 $ D.fillSep [D.blue "Just","width","->"]
1520+ , D.indent 6 $ D.fillSep ["width","+",D.dullyellow "200"]
1559− , 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"]
1561 , D.reflow $
1525 , D.reflow $
1562− "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."
1568− region = toRegion row col
1570− Report.Report "WEIRD DECLARATION" region [] $
1571− Code.toSnippet source region Nothing
1574− "I am trying to parse a declaration, but I am getting stuck here:"
1577 [ D.reflow $
1531 [ D.reflow $
1578− "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?"
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:"
1579 , D.indent 4 $ D.vcat $
1536 , D.indent 4 $ D.vcat $
1580− [ "greet : String -> String"
1537+ [ "greet name ="
1581− , "greet name ="
1538+ , D.fillSep $
1540+ ,D.cyan "if","name","==",D.dullyellow "\"Abraham Lincoln\""
1541+ ,D.cyan "then",D.dullyellow "\"Greetings Mr. President.\""
1582− , " " <> D.dullyellow "\"Hello \"" <> " ++ name ++ " <> D.dullyellow "\"!\""
1542+ ,D.cyan "else",D.dullyellow "\"Hey!\""
1584− , D.cyan "type" <> " User = Anonymous | LoggedIn String"
1586 , D.reflow $
1545 , D.reflow $
1587− "Try to make your declaration look like one of those?"
1546+ "This defines a `reviewPowerLevel` function that you can use elsewhere in your program."
1591− DeclSpace space row col ->
1592− toSpaceReport source space row col
1594− Port port_ row col ->
1595− toPortReport source port_ row col
1597− DeclType declType row col ->
1598− toDeclTypeReport source declType row col
1600− DeclDef name declDef row col ->
1549+ _ ->
1601− toDeclDefReport source name declDef row col
1550+ D.reflow $
1551+ "It is a reserved word. Try changing the name to something else?"
1603− DeclFreshLineAfterDocComment row col ->
1554+ Code.Upper c cs ->
1605 region = toRegion row col
1556 region = toRegion row col
1607− Report.Report "EXPECTING DECLARATION" region [] $
1558+ Report.Report "UNEXPECTED CAPITAL LETTER" region [] $
1608 Code.toSnippet source region Nothing
1559 Code.toSnippet source region Nothing
1610 D.reflow $
1561 D.reflow $
1611− "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:"
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
1613 D.reflow $
1591 D.reflow $
1614− "I was expecting to see the corresponding declaration next, starting on a fresh\
1592+ "I am getting stuck because this line starts with the " ++ [char] ++ " symbol:"
1615− \ line with no indentation."
1593+ ,
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?"
@@ -2575,7 +2591,7 @@ toExprReport source context expr startRow startCol =
2575 ,"give","a","more","specific","hint!"
2591 ,"give","a","more","specific","hint!"
2577 , D.toSimpleNote $
2593 , D.toSimpleNote $
2578− "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.\
2579 \ Or if I run into operators in unexpected spots. Point is, there are a\
2595 \ Or if I run into operators in unexpected spots. Point is, there are a\
2580 \ couple ways I can get confused and give sort of weird advice!"
2596 \ couple ways I can get confused and give sort of weird advice!"