@@ -449,8 +449,8 @@ data TTuple
449449 | TTupleType Type Row Col
450450 | TTupleSpace Space Row Col
451451 --
452− | TTupleIndentOpen Row Col
453− | TTupleIndentType Row Col
452+ | TTupleIndentType1 Row Col
453+ | TTupleIndentTypeN Row Col
454454 | TTupleIndentEnd Row Col
455455
456456
@@ -957,6 +957,13 @@ toWiderRegion row col extra =
957957 (A.Position row (col + extra))
958958
959959
960+toKeywordRegion :: Row -> Col -> [Char.Char] -> A.Region
961+toKeywordRegion row col keyword =
962+ A.Region
963+ (A.Position row col)
964+ (A.Position row (col + fromIntegral (length keyword)))
965+
966+
960967toDeclarationsReport :: Code.Source -> Decl -> Report.Report
961968toDeclarationsReport source decl =
962969 case decl of
@@ -993,7 +1000,7 @@ toDeclDefReport source name declDef startRow startCol =
9931000 Code.Keyword keyword ->
9941001 let
9951002 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
9971004 in
9981005 Report.Report "RESERVED WORD" region [] $
9991006 Code.toSnippet source surroundings (Just region)
@@ -1008,7 +1015,7 @@ toDeclDefReport source name declDef startRow startCol =
10081015 Code.Operator op ->
10091016 let
10101017 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
10121019 in
10131020 Report.Report "UNEXPECTED SYMBOL" region [] $
10141021 Code.toSnippet source surroundings (Just region)
@@ -1816,7 +1823,7 @@ toLetReport source context let_ startRow startCol =
18161823 Code.Keyword keyword ->
18171824 let
18181825 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
18201827 in
18211828 Report.Report "RESERVED WORD" region [] $
18221829 Code.toSnippet source surroundings (Just region)
@@ -1912,12 +1919,12 @@ toCaseReport source context case_ startRow startCol =
19121919 toPatternReport source PCase pattern row col
19131920
19141921 CaseArrow row col ->
1915− let
1916− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1917− region = toRegion row col
1918− in
19191922 case Code.whatIsNext source row col of
19201923 Code.Keyword keyword ->
1924+ let
1925+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1926+ region = toKeywordRegion row col keyword
1927+ in
19211928 Report.Report "RESERVED WORD" region [] $
19221929 Code.toSnippet source surroundings (Just region)
19231930 (
@@ -1930,6 +1937,10 @@ toCaseReport source context case_ startRow startCol =
19301937 )
19311938
19321939 Code.Operator ":" ->
1940+ let
1941+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1942+ region = toRegion row col
1943+ in
19331944 Report.Report "UNEXPECTED OPERATOR" region [] $
19341945 Code.toSnippet source surroundings (Just region)
19351946 (
@@ -1943,6 +1954,10 @@ toCaseReport source context case_ startRow startCol =
19431954 )
19441955
19451956 Code.Operator "=" ->
1957+ let
1958+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1959+ region = toRegion row col
1960+ in
19461961 Report.Report "UNEXPECTED OPERATOR" region [] $
19471962 Code.toSnippet source surroundings (Just region)
19481963 (
@@ -1955,6 +1970,10 @@ toCaseReport source context case_ startRow startCol =
19551970 )
19561971
19571972 _ ->
1973+ let
1974+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1975+ region = toRegion row col
1976+ in
19581977 Report.Report "MISSING ARROW" region [] $
19591978 Code.toSnippet source surroundings (Just region)
19601979 (
@@ -2231,12 +2250,12 @@ toRecordReport :: Code.Source -> Context -> Record -> Row -> Col -> Report.Repor
22312250toRecordReport source context record startRow startCol =
22322251 case record of
22332252 RecordOpen row col ->
2234− let
2235− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2236− region = toRegion row col
2237− in
22382253 case Code.whatIsNext source row col of
22392254 Code.Keyword keyword ->
2255+ let
2256+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2257+ region = toKeywordRegion row col keyword
2258+ in
22402259 Report.Report "RESERVED WORD" region [] $
22412260 Code.toSnippet source surroundings (Just region)
22422261 (
@@ -2249,6 +2268,10 @@ toRecordReport source context record startRow startCol =
22492268 )
22502269
22512270 _ ->
2271+ let
2272+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2273+ region = toRegion row col
2274+ in
22522275 Report.Report "UNFINISHED RECORD" region [] $
22532276 Code.toSnippet source surroundings (Just region)
22542277 (
@@ -2288,7 +2311,7 @@ toRecordReport source context record startRow startCol =
22882311 Code.Keyword keyword ->
22892312 let
22902313 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
22922315 in
22932316 Report.Report "RESERVED WORD" region [] $
22942317 Code.toSnippet source surroundings (Just region)
@@ -2578,7 +2601,7 @@ toTupleReport source context tuple startRow startCol =
25782601 Code.toSnippet source surroundings (Just region)
25792602 (
25802603 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."
25822605 ,
25832606 D.stack
25842607 [ D.fillSep $
@@ -2807,12 +2830,12 @@ toFuncReport source context func startRow startCol =
28072830 toExprReport source (InNode NFunc startRow startCol context) expr row col
28082831
28092832 FuncArrow row col ->
2810− let
2811− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2812− region = toRegion row col
2813− in
28142833 case Code.whatIsNext source row col of
28152834 Code.Keyword keyword ->
2835+ let
2836+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2837+ region = toKeywordRegion row col keyword
2838+ in
28162839 Report.Report "RESERVED WORD" region [] $
28172840 Code.toSnippet source surroundings (Just region)
28182841 (
@@ -2825,6 +2848,10 @@ toFuncReport source context func startRow startCol =
28252848 )
28262849
28272850 _ ->
2851+ let
2852+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2853+ region = toRegion row col
2854+ in
28282855 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
28292856 Code.toSnippet source surroundings (Just region)
28302857 (
@@ -2938,7 +2965,7 @@ toPatternReport source context pattern startRow startCol =
29382965 Code.Keyword keyword ->
29392966 let
29402967 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
29422969 aThing =
29432970 case context of
29442971 PArg -> "an argument"
@@ -3079,7 +3106,7 @@ toPRecordReport source record startRow startCol =
30793106 Code.Keyword keyword ->
30803107 let
30813108 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
30833110 in
30843111 Report.Report "RESERVED WORD" region [] $
30853112 Code.toSnippet source surroundings (Just region)
@@ -3145,7 +3172,7 @@ toPTupleReport source context tuple startRow startCol =
31453172 Code.Keyword keyword ->
31463173 let
31473174 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
31493176 in
31503177 Report.Report "RESERVED WORD" region [] $
31513178 Code.toSnippet source surroundings (Just region)
@@ -3264,7 +3291,7 @@ toPListReport source context list startRow startCol =
32643291 Code.Keyword keyword ->
32653292 let
32663293 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
32683295 in
32693296 Report.Report "RESERVED WORD" region [] $
32703297 Code.toSnippet source surroundings (Just region)
@@ -3403,12 +3430,12 @@ toTRecordReport :: Code.Source -> TRecord -> Row -> Col -> Report.Report
34033430toTRecordReport source record startRow startCol =
34043431 case record of
34053432 TRecordOpen row col ->
3406− let
3407− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3408− region = toRegion row col
3409− in
34103433 case Code.whatIsNext source row col of
34113434 Code.Keyword keyword ->
3435+ let
3436+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3437+ region = toKeywordRegion row col keyword
3438+ in
34123439 Report.Report "RESERVED WORD" region [] $
34133440 Code.toSnippet source surroundings (Just region)
34143441 (
@@ -3421,6 +3448,10 @@ toTRecordReport source record startRow startCol =
34213448 )
34223449
34233450 _ ->
3451+ let
3452+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3453+ region = toRegion row col
3454+ in
34243455 Report.Report "UNFINISHED RECORD TYPE" region [] $
34253456 Code.toSnippet source surroundings (Just region)
34263457 (
@@ -3460,7 +3491,7 @@ toTRecordReport source record startRow startCol =
34603491 Code.Keyword keyword ->
34613492 let
34623493 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
34643495 in
34653496 Report.Report "RESERVED WORD" region [] $
34663497 Code.toSnippet source surroundings (Just region)
@@ -3650,22 +3681,128 @@ toTTupleReport :: Code.Source -> TTuple -> Row -> Col -> Report.Report
36503681toTTupleReport source tuple startRow startCol =
36513682 case tuple of
36523683 TTupleOpen row col ->
3653− error "TODO TTupleOpen" row col startRow startCol
3684+ case Code.whatIsNext source row col of
3685+ Code.Keyword keyword ->
3686+ let
3687+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3688+ region = toKeywordRegion row col keyword
3689+ in
3690+ Report.Report "RESERVED WORD" region [] $
3691+ Code.toSnippet source surroundings (Just region)
3692+ (
3693+ D.reflow $
3694+ "I ran into a reserved word unexpectedly:"
3695+ ,
3696+ D.reflow $
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!"
3699+ )
3700+
3701+ _ ->
3702+ let
3703+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3704+ region = toRegion row col
3705+ in
3706+ Report.Report "UNFINISHED PARENTHESES" region [] $
3707+ Code.toSnippet source surroundings (Just region)
3708+ (
3709+ D.reflow $
3710+ "I just saw an open parenthesis, so I was expecting to see a type next."
3711+ ,
3712+ D.fillSep $
3713+ ["Something","like",D.dullyellow "(Maybe Int)","or"
3714+ ,D.dullyellow "(List Person)" <> "."
3715+ ,"Anything","where","you","are","putting","parentheses","around","normal","types."
3716+ ]
3717+ )
36543718
36553719 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
3723+ in
3724+ Report.Report "UNFINISHED PARENTHESES" region [] $
3725+ Code.toSnippet source surroundings (Just region)
3726+ (
3727+ D.reflow $
3728+ "I was expecting to see a closing parentheses next, but I got stuck here:"
3729+ ,
3730+ D.stack
3731+ [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
3732+ , D.toSimpleNote $
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."
3736+ ]
3737+ )
36573738
36583739 TTupleType tipe row col ->
3659− error "TODO TTupleType" tipe row col
3740+ toTypeReport source tipe row col
36603741
36613742 TTupleSpace space row col ->
36623743 toSpaceReport source space row col
36633744
3664− TTupleIndentOpen row col ->
3665− error "TODO TTupleIndentOpen" row col
3745+ TTupleIndentType1 row col ->
3746+ let
3747+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3748+ region = toRegion row col
3749+ in
3750+ Report.Report "UNFINISHED PARENTHESES" region [] $
3751+ Code.toSnippet source surroundings (Just region)
3752+ (
3753+ D.reflow $
3754+ "I just saw an open parenthesis, so I was expecting to see a type next."
3755+ ,
3756+ D.stack
3757+ [ D.fillSep $
3758+ ["Something","like",D.dullyellow "(Maybe Int)","or"
3759+ ,D.dullyellow "(List Person)" <> "."
3760+ ,"Anything","where","you","are","putting","parentheses","around","normal","types."
3761+ ]
3762+ , D.toSimpleNote $
3763+ "I can get confused by indentation in cases like this, so\
3764+ \ maybe you have a type but it is not indented enough?"
3765+ ]
3766+ )
36663767
3667− TTupleIndentType row col ->
3668− error "TODO TTupleIndentType" row col
3768+ TTupleIndentTypeN row col ->
3769+ let
3770+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3771+ region = toRegion row col
3772+ in
3773+ Report.Report "UNFINISHED TUPLE TYPE" region [] $
3774+ Code.toSnippet source surroundings (Just region)
3775+ (
3776+ D.reflow $
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."
3778+ ,
3779+ D.stack
3780+ [ D.fillSep $
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?"
3784+ ]
3785+ , D.toSimpleNote $
3786+ "I can get confused by indentation in cases like this, so\
3787+ \ maybe you have an expression but it is not indented enough?"
3788+ ]
3789+ )
36693790
36703791 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
3795+ in
3796+ Report.Report "UNFINISHED PARENTHESES" region [] $
3797+ Code.toSnippet source surroundings (Just region)
3798+ (
3799+ D.reflow $
3800+ "I was expecting to see a closing parenthesis next:"
3801+ ,
3802+ D.stack
3803+ [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
3804+ , D.toSimpleNote $
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?"
3807+ ]
3808+ )