@@ -449,8 +449,8 @@ data TTuple
449 | TTupleType Type Row Col
449 | TTupleType Type Row Col
450 | TTupleSpace Space Row Col
450 | TTupleSpace Space Row Col
452− | TTupleIndentOpen Row Col
452+ | TTupleIndentType1 Row Col
453− | TTupleIndentType Row Col
453+ | TTupleIndentTypeN Row Col
454 | TTupleIndentEnd Row Col
454 | TTupleIndentEnd Row Col
@@ -957,6 +957,13 @@ toWiderRegion row col extra =
957 (A.Position row (col + extra))
957 (A.Position row (col + extra))
960+toKeywordRegion :: Row -> Col -> [Char.Char] -> A.Region
961+toKeywordRegion row col keyword =
963+ (A.Position row col)
964+ (A.Position row (col + fromIntegral (length keyword)))
960toDeclarationsReport :: Code.Source -> Decl -> Report.Report
967toDeclarationsReport :: Code.Source -> Decl -> Report.Report
961toDeclarationsReport source decl =
968toDeclarationsReport source decl =
962 case decl of
969 case decl of
@@ -993,7 +1000,7 @@ toDeclDefReport source name declDef startRow startCol =
993 Code.Keyword keyword ->
1000 Code.Keyword keyword ->
995 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1002 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
996− region = toWiderRegion row col (fromIntegral (length keyword))
1003+ region = toKeywordRegion row col keyword
998 Report.Report "RESERVED WORD" region [] $
1005 Report.Report "RESERVED WORD" region [] $
999 Code.toSnippet source surroundings (Just region)
1006 Code.toSnippet source surroundings (Just region)
@@ -1008,7 +1015,7 @@ toDeclDefReport source name declDef startRow startCol =
1008 Code.Operator op ->
1015 Code.Operator op ->
1010 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1017 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1011− region = toWiderRegion row col (fromIntegral (length op))
1018+ region = toKeywordRegion row col op
1013 Report.Report "UNEXPECTED SYMBOL" region [] $
1020 Report.Report "UNEXPECTED SYMBOL" region [] $
1014 Code.toSnippet source surroundings (Just region)
1021 Code.toSnippet source surroundings (Just region)
@@ -1816,7 +1823,7 @@ toLetReport source context let_ startRow startCol =
1816 Code.Keyword keyword ->
1823 Code.Keyword keyword ->
1818 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1825 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1819− region = toWiderRegion row col (fromIntegral (length keyword))
1826+ region = toKeywordRegion row col keyword
1821 Report.Report "RESERVED WORD" region [] $
1828 Report.Report "RESERVED WORD" region [] $
1822 Code.toSnippet source surroundings (Just region)
1829 Code.toSnippet source surroundings (Just region)
@@ -1912,12 +1919,12 @@ toCaseReport source context case_ startRow startCol =
1912 toPatternReport source PCase pattern row col
1919 toPatternReport source PCase pattern row col
1914 CaseArrow row col ->
1921 CaseArrow row col ->
1916− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1917− region = toRegion row col
1919 case Code.whatIsNext source row col of
1922 case Code.whatIsNext source row col of
1920 Code.Keyword keyword ->
1923 Code.Keyword keyword ->
1925+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1926+ region = toKeywordRegion row col keyword
1921 Report.Report "RESERVED WORD" region [] $
1928 Report.Report "RESERVED WORD" region [] $
1922 Code.toSnippet source surroundings (Just region)
1929 Code.toSnippet source surroundings (Just region)
@@ -1930,6 +1937,10 @@ toCaseReport source context case_ startRow startCol =
1932 Code.Operator ":" ->
1939 Code.Operator ":" ->
1941+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1942+ region = toRegion row col
1933 Report.Report "UNEXPECTED OPERATOR" region [] $
1944 Report.Report "UNEXPECTED OPERATOR" region [] $
1934 Code.toSnippet source surroundings (Just region)
1945 Code.toSnippet source surroundings (Just region)
@@ -1943,6 +1954,10 @@ toCaseReport source context case_ startRow startCol =
1945 Code.Operator "=" ->
1956 Code.Operator "=" ->
1958+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1959+ region = toRegion row col
1946 Report.Report "UNEXPECTED OPERATOR" region [] $
1961 Report.Report "UNEXPECTED OPERATOR" region [] $
1947 Code.toSnippet source surroundings (Just region)
1962 Code.toSnippet source surroundings (Just region)
@@ -1955,6 +1970,10 @@ toCaseReport source context case_ startRow startCol =
1974+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1975+ region = toRegion row col
1958 Report.Report "MISSING ARROW" region [] $
1977 Report.Report "MISSING ARROW" region [] $
1959 Code.toSnippet source surroundings (Just region)
1978 Code.toSnippet source surroundings (Just region)
@@ -2231,12 +2250,12 @@ toRecordReport :: Code.Source -> Context -> Record -> Row -> Col -> Report.Repor
2231toRecordReport source context record startRow startCol =
2250toRecordReport source context record startRow startCol =
2232 case record of
2251 case record of
2233 RecordOpen row col ->
2252 RecordOpen row col ->
2235− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2236− region = toRegion row col
2238 case Code.whatIsNext source row col of
2253 case Code.whatIsNext source row col of
2239 Code.Keyword keyword ->
2254 Code.Keyword keyword ->
2256+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2257+ region = toKeywordRegion row col keyword
2240 Report.Report "RESERVED WORD" region [] $
2259 Report.Report "RESERVED WORD" region [] $
2241 Code.toSnippet source surroundings (Just region)
2260 Code.toSnippet source surroundings (Just region)
@@ -2249,6 +2268,10 @@ toRecordReport source context record startRow startCol =
2272+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2273+ region = toRegion row col
2252 Report.Report "UNFINISHED RECORD" region [] $
2275 Report.Report "UNFINISHED RECORD" region [] $
2253 Code.toSnippet source surroundings (Just region)
2276 Code.toSnippet source surroundings (Just region)
@@ -2288,7 +2311,7 @@ toRecordReport source context record startRow startCol =
2288 Code.Keyword keyword ->
2311 Code.Keyword keyword ->
2290 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2313 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2291− region = toWiderRegion row col (fromIntegral (length keyword))
2314+ region = toKeywordRegion row col keyword
2293 Report.Report "RESERVED WORD" region [] $
2316 Report.Report "RESERVED WORD" region [] $
2294 Code.toSnippet source surroundings (Just region)
2317 Code.toSnippet source surroundings (Just region)
@@ -2578,7 +2601,7 @@ toTupleReport source context tuple startRow startCol =
2578 Code.toSnippet source surroundings (Just region)
2601 Code.toSnippet source surroundings (Just region)
2580 D.reflow $
2603 D.reflow $
2581− "I think I am in the middle of parsing a tuple. I just saw a comma, so I was expecting to see expression next."
2604+ "I think I am in the middle of parsing a tuple. I just saw a comma, so I was expecting to see an expression next."
2584 [ D.fillSep $
2607 [ D.fillSep $
@@ -2807,12 +2830,12 @@ toFuncReport source context func startRow startCol =
2807 toExprReport source (InNode NFunc startRow startCol context) expr row col
2830 toExprReport source (InNode NFunc startRow startCol context) expr row col
2809 FuncArrow row col ->
2832 FuncArrow row col ->
2811− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2812− region = toRegion row col
2814 case Code.whatIsNext source row col of
2833 case Code.whatIsNext source row col of
2815 Code.Keyword keyword ->
2834 Code.Keyword keyword ->
2836+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2837+ region = toKeywordRegion row col keyword
2816 Report.Report "RESERVED WORD" region [] $
2839 Report.Report "RESERVED WORD" region [] $
2817 Code.toSnippet source surroundings (Just region)
2840 Code.toSnippet source surroundings (Just region)
@@ -2825,6 +2848,10 @@ toFuncReport source context func startRow startCol =
2852+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2853+ region = toRegion row col
2828 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
2855 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
2829 Code.toSnippet source surroundings (Just region)
2856 Code.toSnippet source surroundings (Just region)
@@ -2938,7 +2965,7 @@ toPatternReport source context pattern startRow startCol =
2938 Code.Keyword keyword ->
2965 Code.Keyword keyword ->
2940 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2967 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2941− region = toWiderRegion row col (fromIntegral (length keyword))
2968+ region = toKeywordRegion row col keyword
2942 aThing =
2969 aThing =
2943 case context of
2970 case context of
2944 PArg -> "an argument"
2971 PArg -> "an argument"
@@ -3079,7 +3106,7 @@ toPRecordReport source record startRow startCol =
3079 Code.Keyword keyword ->
3106 Code.Keyword keyword ->
3081 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3108 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3082− region = toWiderRegion row col (fromIntegral (length keyword))
3109+ region = toKeywordRegion row col keyword
3084 Report.Report "RESERVED WORD" region [] $
3111 Report.Report "RESERVED WORD" region [] $
3085 Code.toSnippet source surroundings (Just region)
3112 Code.toSnippet source surroundings (Just region)
@@ -3145,7 +3172,7 @@ toPTupleReport source context tuple startRow startCol =
3145 Code.Keyword keyword ->
3172 Code.Keyword keyword ->
3147 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3174 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3148− region = toWiderRegion row col (fromIntegral (length keyword))
3175+ region = toKeywordRegion row col keyword
3150 Report.Report "RESERVED WORD" region [] $
3177 Report.Report "RESERVED WORD" region [] $
3151 Code.toSnippet source surroundings (Just region)
3178 Code.toSnippet source surroundings (Just region)
@@ -3264,7 +3291,7 @@ toPListReport source context list startRow startCol =
3264 Code.Keyword keyword ->
3291 Code.Keyword keyword ->
3266 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3293 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3267− region = toWiderRegion row col (fromIntegral (length keyword))
3294+ region = toKeywordRegion row col keyword
3269 Report.Report "RESERVED WORD" region [] $
3296 Report.Report "RESERVED WORD" region [] $
3270 Code.toSnippet source surroundings (Just region)
3297 Code.toSnippet source surroundings (Just region)
@@ -3403,12 +3430,12 @@ toTRecordReport :: Code.Source -> TRecord -> Row -> Col -> Report.Report
3403toTRecordReport source record startRow startCol =
3430toTRecordReport source record startRow startCol =
3404 case record of
3431 case record of
3405 TRecordOpen row col ->
3432 TRecordOpen row col ->
3407− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3408− region = toRegion row col
3410 case Code.whatIsNext source row col of
3433 case Code.whatIsNext source row col of
3411 Code.Keyword keyword ->
3434 Code.Keyword keyword ->
3436+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3437+ region = toKeywordRegion row col keyword
3412 Report.Report "RESERVED WORD" region [] $
3439 Report.Report "RESERVED WORD" region [] $
3413 Code.toSnippet source surroundings (Just region)
3440 Code.toSnippet source surroundings (Just region)
@@ -3421,6 +3448,10 @@ toTRecordReport source record startRow startCol =
3452+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3453+ region = toRegion row col
3424 Report.Report "UNFINISHED RECORD TYPE" region [] $
3455 Report.Report "UNFINISHED RECORD TYPE" region [] $
3425 Code.toSnippet source surroundings (Just region)
3456 Code.toSnippet source surroundings (Just region)
@@ -3460,7 +3491,7 @@ toTRecordReport source record startRow startCol =
3460 Code.Keyword keyword ->
3491 Code.Keyword keyword ->
3462 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3493 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3463− region = toWiderRegion row col (fromIntegral (length keyword))
3494+ region = toKeywordRegion row col keyword
3465 Report.Report "RESERVED WORD" region [] $
3496 Report.Report "RESERVED WORD" region [] $
3466 Code.toSnippet source surroundings (Just region)
3497 Code.toSnippet source surroundings (Just region)
@@ -3650,22 +3681,128 @@ toTTupleReport :: Code.Source -> TTuple -> Row -> Col -> Report.Report
3650toTTupleReport source tuple startRow startCol =
3681toTTupleReport source tuple startRow startCol =
3651 case tuple of
3682 case tuple of
3652 TTupleOpen row col ->
3683 TTupleOpen row col ->
3653− error "TODO TTupleOpen" row col startRow startCol
3684+ case Code.whatIsNext source row col of
3685+ Code.Keyword keyword ->
3687+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3688+ region = toKeywordRegion row col keyword
3690+ Report.Report "RESERVED WORD" region [] $
3691+ Code.toSnippet source surroundings (Just region)
3694+ "I ran into a reserved word unexpectedly:"
3697+ "It looks like you are trying to use `" ++ keyword ++ "` as a variable name, but \
3698+ \ it is a reserved word. Try using a different name!"
3703+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3704+ region = toRegion row col
3706+ Report.Report "UNFINISHED PARENTHESES" region [] $
3707+ Code.toSnippet source surroundings (Just region)
3710+ "I just saw an open parenthesis, so I was expecting to see a type next."
3713+ ["Something","like",D.dullyellow "(Maybe Int)","or"
3714+ ,D.dullyellow "(List Person)" <> "."
3715+ ,"Anything","where","you","are","putting","parentheses","around","normal","types."
3655 TTupleEnd row col ->
3719 TTupleEnd row col ->
3656− error "TODO TTupleEnd" row col
3720+ let
3721+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3722+ region = toRegion row col
3724+ Report.Report "UNFINISHED PARENTHESES" region [] $
3725+ Code.toSnippet source surroundings (Just region)
3728+ "I was expecting to see a closing parentheses next, but I got stuck here:"
3731+ [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
3733+ "I can get stuck when I run into keywords, operators, parentheses, or brackets\
3734+ \ unexpectedly. So there may be some earlier syntax trouble (like extra parenthesis\
3735+ \ or missing brackets) that is confusing me."
3658 TTupleType tipe row col ->
3739 TTupleType tipe row col ->
3659− error "TODO TTupleType" tipe row col
3740+ toTypeReport source tipe row col
3661 TTupleSpace space row col ->
3742 TTupleSpace space row col ->
3662 toSpaceReport source space row col
3743 toSpaceReport source space row col
3664− TTupleIndentOpen row col ->
3745+ TTupleIndentType1 row col ->
3665− error "TODO TTupleIndentOpen" row col
3746+ let
3747+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3748+ region = toRegion row col
3750+ Report.Report "UNFINISHED PARENTHESES" region [] $
3751+ Code.toSnippet source surroundings (Just region)
3754+ "I just saw an open parenthesis, so I was expecting to see a type next."
3758+ ["Something","like",D.dullyellow "(Maybe Int)","or"
3759+ ,D.dullyellow "(List Person)" <> "."
3760+ ,"Anything","where","you","are","putting","parentheses","around","normal","types."
3763+ "I can get confused by indentation in cases like this, so\
3764+ \ maybe you have a type but it is not indented enough?"
3667− TTupleIndentType row col ->
3768+ TTupleIndentTypeN row col ->
3668− error "TODO TTupleIndentType" row col
3769+ let
3770+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3771+ region = toRegion row col
3773+ Report.Report "UNFINISHED TUPLE TYPE" region [] $
3774+ Code.toSnippet source surroundings (Just region)
3777+ "I think I am in the middle of parsing a tuple type. I just saw a comma, so I was expecting to see a type next."
3781+ ["A","tuple","type","looks","like",D.dullyellow "(Float,Float)","or"
3782+ ,D.dullyellow "(String,Int)" <> ","
3783+ ,"so","I","think","there","is","a","type","missing","here?"
3786+ "I can get confused by indentation in cases like this, so\
3787+ \ maybe you have an expression but it is not indented enough?"
3670 TTupleIndentEnd row col ->
3791 TTupleIndentEnd row col ->
3671− error "TODO TTupleIndentEnd" row col
3792+ let
3793+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3794+ region = toRegion row col
3796+ Report.Report "UNFINISHED PARENTHESES" region [] $
3797+ Code.toSnippet source surroundings (Just region)
3800+ "I was expecting to see a closing parenthesis next:"
3803+ [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
3805+ "I can get confused by indentation in cases like this, so\
3806+ \ maybe you have a closing parenthesis but it is not indented enough?"