@@ -134,7 +134,6 @@ data Decl
134 | DeclType DeclType Row Col
134 | DeclType DeclType Row Col
135 | DeclDef Name.Name DeclDef Row Col
135 | DeclDef Name.Name DeclDef Row Col
137− | DeclFreshLineStart Row Col
138 | DeclFreshLineAfterDocComment Row Col
137 | DeclFreshLineAfterDocComment Row Col
@@ -408,7 +407,6 @@ data PList
409 = TRecord TRecord Row Col
408 = TRecord TRecord Row Col
410 | TTuple TTuple Row Col
409 | TTuple TTuple Row Col
413 | TStart Row Col
411 | TStart Row Col
414 | TSpace Space Row Col
412 | TSpace Space Row Col
@@ -1234,7 +1232,106 @@ toDeclarationsReport :: Code.Source -> Decl -> Report.Report
1234toDeclarationsReport source decl =
1232toDeclarationsReport source decl =
1235 case decl of
1233 case decl of
1236 DeclStart row col ->
1234 DeclStart row col ->
1237− error "TODO DeclStart" row col
1235+ case Code.whatIsNext source row col of
1236+ Code.Close term _ ->
1238+ region = toRegion row col
1240+ Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
1241+ Code.toSnippet source region Nothing
1244+ "I was not expecting to see a " ++ term ++ " here:"
1246+ "It does not match up with anything. Maybe try deleting it?"
1249+ Code.Keyword keyword ->
1251+ region = toKeywordRegion row col keyword
1253+ Report.Report "RESERVED WORD" region [] $
1254+ Code.toSnippet source region Nothing
1257+ "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
1262+ "It is reserved for declaring imports at the top of your module. If you want\
1263+ \ another import, try moving it up top with the other imports. If you want to\
1264+ \ define a value or function, try changing the name to something else!"
1269+ "It is reserved for writing `case` expressions. Try using a different name?"
1271+ "If you are trying to write a `case` expression, it needs to be part of a\
1272+ \ definition. So you could write something like this instead:"
1274+ [ D.indent 0 $ D.fillSep [D.green "getWidth","maybeWidth","="]
1275+ , D.indent 2 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
1276+ , D.indent 4 $ D.fillSep [D.blue "Just","width","->"]
1277+ , D.indent 6 $ D.fillSep ["width","+",D.dullyellow "200"]
1279+ , D.indent 4 $ D.fillSep [D.blue "Nothing","->"]
1280+ , D.indent 6 $ D.fillSep [D.dullyellow "400"]
1283+ "This defines a `getWidth` function that we can use elsewhere in our program."
1289+ "It is reserved for writing `if` expressions. Try using a different name?"
1291+ "If you are trying to write an `if` expression, it needs to be part of a\
1292+ \ definition. So you could write something like this instead:"
1294+ [ D.indent 0 $ D.fillSep [D.green "reviewPowerLevel","powerLevel","="]
1295+ , D.indent 2 $ D.fillSep $
1296+ [D.cyan "if","powerLevel",">",D.dullyellow "9000"
1297+ ,D.cyan "then",D.dullyellow "\"OVER 9000!!!\""
1298+ ,D.cyan "else",D.dullyellow "\"not bad\""
1302+ "This defines a `reviewPowerLevel` function that we can use elsewhere in our program."
1307+ "It is a reserved word. Try changing the name to something else?"
1312+ region = toRegion row col
1314+ Report.Report "SYNTAX PROBLEM" region [] $
1315+ Code.toSnippet source region Nothing
1318+ "I was expecting to see a new declaration here:"
1322+ "I am not sure what is going wrong exactly, but here are a couple valid\
1323+ \ declarations for reference:"
1325+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
1326+ , D.fillSep [D.green "add","x","y","="]
1327+ , D.fillSep [" ","x","+","y"]
1329+ , D.fillSep [D.cyan "type",D.green "User","=","Anonymous","|","LoggedIn String"]
1331+ "Note that all declarations start with lower-case letters in Elm. Capitalization\
1332+ \ makes a difference, so be consious of that if you are working from examples!"
1239 DeclSpace space row col ->
1336 DeclSpace space row col ->
1240 toSpaceReport source space row col
1337 toSpaceReport source space row col
@@ -1248,11 +1345,20 @@ toDeclarationsReport source decl =
1248 DeclDef name declDef row col ->
1345 DeclDef name declDef row col ->
1249 toDeclDefReport source name declDef row col
1346 toDeclDefReport source name declDef row col
1251− DeclFreshLineStart row col ->
1252− error "TODO DeclFreshLineStart" row col
1254 DeclFreshLineAfterDocComment row col ->
1348 DeclFreshLineAfterDocComment row col ->
1255− error "TODO DeclFreshLineAfterDocComment" row col
1349+ let
1350+ region = toRegion row col
1352+ Report.Report "EXPECTING DECLARATION" region [] $
1353+ Code.toSnippet source region Nothing
1356+ "I just saw a doc comment, but then I got stuck here:"
1359+ "I was expecting to see the corresponding declaration next, starting on a fresh\
1360+ \ line with no indentation."
@@ -1324,7 +1430,7 @@ toPortReport source port_ startRow startCol =
1326 PortType tipe row col ->
1432 PortType tipe row col ->
1327− toTypeReport source tipe row col
1433+ toTypeReport source TC_Port tipe row col
1329 PortIndentName row col ->
1435 PortIndentName row col ->
@@ -1536,7 +1642,7 @@ toTypeAliasReport source typeAlias startRow startCol =
1538 AliasBody tipe row col ->
1644 AliasBody tipe row col ->
1539− toTypeReport source tipe row col
1645+ toTypeReport source TC_TypeAlias tipe row col
1541 AliasIndentEquals row col ->
1647 AliasIndentEquals row col ->
@@ -1703,7 +1809,7 @@ toCustomTypeReport source customType startRow startCol =
1705 CT_VariantArg tipe row col ->
1811 CT_VariantArg tipe row col ->
1706− toTypeReport source tipe row col
1812+ toTypeReport source TC_CustomType tipe row col
1708 CT_IndentEquals row col ->
1814 CT_IndentEquals row col ->
@@ -1876,7 +1982,7 @@ toDeclDefReport source name declDef startRow startCol =
1878 DeclDefType tipe row col ->
1984 DeclDefType tipe row col ->
1879− toTypeReport source tipe row col
1985+ toTypeReport source (TC_Annotation name) tipe row col
1881 DeclDefArg pattern row col ->
1987 DeclDefArg pattern row col ->
1882 toPatternReport source PArg pattern row col
1988 toPatternReport source PArg pattern row col
@@ -2916,10 +3022,10 @@ toUnfinishCaseReport source row col startRow startCol message =
2916 "Here is an example of a valid `case` expression for reference."
3022 "Here is an example of a valid `case` expression for reference."
2917 , D.vcat $
3023 , D.vcat $
2918 [ D.indent 4 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
3024 [ D.indent 4 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
2919− , D.indent 6 $ D.fillSep [D.green "Just","width","->"]
3025+ , D.indent 6 $ D.fillSep [D.blue "Just","width","->"]
2920 , D.indent 8 $ D.fillSep ["width","+",D.dullyellow "200"]
3026 , D.indent 8 $ D.fillSep ["width","+",D.dullyellow "200"]
2922− , D.indent 6 $ D.fillSep [D.green "Nothing","->"]
3028+ , D.indent 6 $ D.fillSep [D.blue "Nothing","->"]
2923 , D.indent 8 $ D.fillSep [D.dullyellow "400"]
3029 , D.indent 8 $ D.fillSep [D.dullyellow "400"]
2925 , D.reflow $
3031 , D.reflow $
@@ -2939,10 +3045,10 @@ addNoteForCaseIndentError message =
2939 \ something like this:"
3045 \ something like this:"
2940 , D.vcat $
3046 , D.vcat $
2941 [ D.indent 4 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
3047 [ D.indent 4 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
2942− , D.indent 6 $ D.fillSep [D.green "Just","width","->"]
3048+ , D.indent 6 $ D.fillSep [D.blue "Just","width","->"]
2943 , D.indent 8 $ D.fillSep ["width","+",D.dullyellow "200"]
3049 , D.indent 8 $ D.fillSep ["width","+",D.dullyellow "200"]
2945− , D.indent 6 $ D.fillSep [D.green "Nothing","->"]
3051+ , D.indent 6 $ D.fillSep [D.blue "Nothing","->"]
2946 , D.indent 8 $ D.fillSep [D.dullyellow "400"]
3052 , D.indent 8 $ D.fillSep [D.dullyellow "400"]
2948 , D.reflow $
3054 , D.reflow $
@@ -3326,7 +3432,7 @@ toRecordReport source context record startRow startCol =
3327 addNoteForRecordIndentError $
3433 addNoteForRecordIndentError $
3328 D.fillSep $
3434 D.fillSep $
3329− ["Try","putting","something,","like"
3435+ ["Try","putting","something","like"
3330 ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
3436 ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
@@ -4276,33 +4382,106 @@ toPListReport source context list startRow startCol =
4279−-- TODO add context? say something special if you are in type annotation vs custom type vs type alias?
4385+data TContext
4280−--
4386+ = TC_Annotation Name.Name
4281−toTypeReport :: Code.Source -> Type -> Row -> Col -> Report.Report
4392+toTypeReport :: Code.Source -> TContext -> Type -> Row -> Col -> Report.Report
4282−toTypeReport source tipe startRow startCol =
4393+toTypeReport source context tipe startRow startCol =
4283 case tipe of
4394 case tipe of
4284 TRecord record row col ->
4395 TRecord record row col ->
4285− toTRecordReport source record row col
4396+ toTRecordReport source context record row col
4287 TTuple tuple row col ->
4398 TTuple tuple row col ->
4288− toTTupleReport source tuple row col
4399+ toTTupleReport source context tuple row col
4291− error "TODO TArrow" row col
4293 TStart row col ->
4401 TStart row col ->
4294− error "TODO TStart" row col startRow startCol
4402+ case Code.whatIsNext source row col of
4403+ Code.Keyword keyword ->
4405+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4406+ region = toKeywordRegion row col keyword
4408+ Report.Report "RESERVED WORD" region [] $
4409+ Code.toSnippet source surroundings (Just region)
4412+ "I was expecting to see a type next, but I got stuck on this reserved word:"
4415+ "It looks like you are trying to use `" ++ keyword ++ "` as a type variable, but \
4416+ \ it is a reserved word. Try using a different name!"
4421+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4422+ region = toRegion row col
4426+ TC_Annotation _ -> "type annotation"
4427+ TC_CustomType -> "custom type"
4428+ TC_TypeAlias -> "type alias"
4433+ TC_Annotation name -> "the `" ++ Name.toChars name ++ "` type annotation"
4434+ TC_CustomType -> "a custom type"
4435+ TC_TypeAlias -> "a type alias"
4436+ TC_Port -> "a port"
4438+ Report.Report ("PROBLEM IN " ++ map Char.toUpper thing) region [] $
4439+ Code.toSnippet source surroundings (Just region)
4442+ "I was partway through parsing " ++ something ++ ", but I got stuck here:"
4445+ ["I","was","expecting","to","see","a","type","next."
4446+ ,"Try","putting",D.dullyellow "Int","or",D.dullyellow "String","for","now?"
4296 TSpace space row col ->
4450 TSpace space row col ->
4297 toSpaceReport source space row col
4451 toSpaceReport source space row col
4299 TIndentStart row col ->
4453 TIndentStart row col ->
4300− error "TODO TIndentStart" row col
4454+ let
4455+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4456+ region = toRegion row col
4460+ TC_Annotation _ -> "type annotation"
4461+ TC_CustomType -> "custom type"
4462+ TC_TypeAlias -> "type alias"
4465+ Report.Report ("UNFINISHED " ++ map Char.toUpper thing) region [] $
4466+ Code.toSnippet source surroundings (Just region)
4469+ "I was partway through parsing a " ++ thing ++ ", but I got stuck here:"
4473+ ["I","was","expecting","to","see","a","type","next."
4474+ ,"Try","putting",D.dullyellow "Int","or",D.dullyellow "String","for","now?"
4477+ "I can get confused by indentation. If you think there is already a type\
4478+ \ next, maybe it is not indented enough?"
4304−toTRecordReport :: Code.Source -> TRecord -> Row -> Col -> Report.Report
4483+toTRecordReport :: Code.Source -> TContext -> TRecord -> Row -> Col -> Report.Report
4305−toTRecordReport source record startRow startCol =
4484+toTRecordReport source context record startRow startCol =
4306 case record of
4485 case record of
4307 TRecordOpen row col ->
4486 TRecordOpen row col ->
4308 case Code.whatIsNext source row col of
4487 case Code.whatIsNext source row col of
@@ -4416,7 +4595,7 @@ toTRecordReport source record startRow startCol =
4418 TRecordType tipe row col ->
4597 TRecordType tipe row col ->
4419− toTypeReport source tipe row col
4598+ toTypeReport source context tipe row col
4421 TRecordSpace space row col ->
4600 TRecordSpace space row col ->
4422 toSpaceReport source space row col
4601 toSpaceReport source space row col
@@ -4505,7 +4684,7 @@ toTRecordReport source record startRow startCol =
4506 addNoteForRecordTypeIndentError $
4685 addNoteForRecordTypeIndentError $
4507 D.fillSep $
4686 D.fillSep $
4508− ["Try","putting","something,","like"
4687+ ["Try","putting","something","like"
4509 ,D.dullyellow "Int","or",D.dullyellow "String","for","now?"
4688 ,D.dullyellow "Int","or",D.dullyellow "String","for","now?"
@@ -4552,8 +4731,8 @@ addNoteForRecordTypeIndentError normalRecommendation =
4555−toTTupleReport :: Code.Source -> TTuple -> Row -> Col -> Report.Report
4734+toTTupleReport :: Code.Source -> TContext -> TTuple -> Row -> Col -> Report.Report
4556−toTTupleReport source tuple startRow startCol =
4735+toTTupleReport source context tuple startRow startCol =
4557 case tuple of
4736 case tuple of
4558 TTupleOpen row col ->
4737 TTupleOpen row col ->
4559 case Code.whatIsNext source row col of
4738 case Code.whatIsNext source row col of
@@ -4612,7 +4791,7 @@ toTTupleReport source tuple startRow startCol =
4614 TTupleType tipe row col ->
4793 TTupleType tipe row col ->
4615− toTypeReport source tipe row col
4794+ toTypeReport source context tipe row col
4617 TTupleSpace space row col ->
4796 TTupleSpace space row col ->
4618 toSpaceReport source space row col
4797 toSpaceReport source space row col