on master help sign in
Fill in tuple type syntax messages / underline keywords more often
4520afeEvan Czaplicki
compiler/src/Parse/Type.hs+2−2
@@ -47,7 +47,7 @@ term =
47 oneOf E.TTupleOpen
47 oneOf E.TTupleOpen
48 [ do word1 0x29 {-)-} E.TTupleOpen
48 [ do word1 0x29 {-)-} E.TTupleOpen
49 addEnd start Src.TUnit
49 addEnd start Src.TUnit
50− , do Space.chompAndCheckIndent E.TTupleSpace E.TTupleIndentType
50+ , do Space.chompAndCheckIndent E.TTupleSpace E.TTupleIndentType1
51 (tipe, end) <- specialize E.TTupleType expression
51 (tipe, end) <- specialize E.TTupleType expression
52 Space.checkIndent end E.TTupleIndentEnd
52 Space.checkIndent end E.TTupleIndentEnd
53 chompTupleEnd start tipe []
53 chompTupleEnd start tipe []
@@ -147,7 +147,7 @@ chompTupleEnd :: A.Position -> Src.Type -> [Src.Type] -> Parser E.TTuple Src.Typ
147chompTupleEnd start firstType revTypes =
147chompTupleEnd start firstType revTypes =
148 oneOf E.TTupleEnd
148 oneOf E.TTupleEnd
149 [ do word1 0x2C {-,-} E.TTupleEnd
149 [ do word1 0x2C {-,-} E.TTupleEnd
150− Space.chompAndCheckIndent E.TTupleSpace E.TTupleIndentType
150+ Space.chompAndCheckIndent E.TTupleSpace E.TTupleIndentTypeN
151 (tipe, end) <- specialize E.TTupleType expression
151 (tipe, end) <- specialize E.TTupleType expression
152 Space.checkIndent end E.TTupleIndentEnd
152 Space.checkIndent end E.TTupleIndentEnd
153 chompTupleEnd start firstType (tipe : revTypes)
153 chompTupleEnd start firstType (tipe : revTypes)
compiler/src/Reporting/Error/Syntax.hs+173−36
@@ -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
451 --
451 --
452− | TTupleIndentOpen Row Col
452+ | TTupleIndentType1 Row Col
453− | TTupleIndentType Row Col
453+ | TTupleIndentTypeN Row Col
454 | TTupleIndentEnd Row Col
454 | TTupleIndentEnd Row Col
455
455
456
456
@@ -957,6 +957,13 @@ toWiderRegion row col extra =
957 (A.Position row (col + extra))
957 (A.Position row (col + extra))
958
958
959
959
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+
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 ->
994 let
1001 let
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
997 in
1004 in
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 ->
1009 let
1016 let
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
1012 in
1019 in
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 ->
1817 let
1824 let
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
1820 in
1827 in
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
1913
1920
1914 CaseArrow row col ->
1921 CaseArrow row col ->
1915− let
1916− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1917− region = toRegion row col
1918− in
1919 case Code.whatIsNext source row col of
1922 case Code.whatIsNext source row col of
1920 Code.Keyword keyword ->
1923 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
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)
1923 (
1930 (
@@ -1930,6 +1937,10 @@ toCaseReport source context case_ startRow startCol =
1930 )
1937 )
1931
1938
1932 Code.Operator ":" ->
1939 Code.Operator ":" ->
1940+ let
1941+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1942+ region = toRegion row col
1943+ in
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)
1935 (
1946 (
@@ -1943,6 +1954,10 @@ toCaseReport source context case_ startRow startCol =
1943 )
1954 )
1944
1955
1945 Code.Operator "=" ->
1956 Code.Operator "=" ->
1957+ let
1958+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1959+ region = toRegion row col
1960+ in
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)
1948 (
1963 (
@@ -1955,6 +1970,10 @@ toCaseReport source context case_ startRow startCol =
1955 )
1970 )
1956
1971
1957 _ ->
1972 _ ->
1973+ let
1974+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1975+ region = toRegion row col
1976+ in
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)
1960 (
1979 (
@@ -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 ->
2234− let
2235− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2236− region = toRegion row col
2237− in
2238 case Code.whatIsNext source row col of
2253 case Code.whatIsNext source row col of
2239 Code.Keyword keyword ->
2254 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
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)
2242 (
2261 (
@@ -2249,6 +2268,10 @@ toRecordReport source context record startRow startCol =
2249 )
2268 )
2250
2269
2251 _ ->
2270 _ ->
2271+ let
2272+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2273+ region = toRegion row col
2274+ in
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)
2254 (
2277 (
@@ -2288,7 +2311,7 @@ toRecordReport source context record startRow startCol =
2288 Code.Keyword keyword ->
2311 Code.Keyword keyword ->
2289 let
2312 let
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
2292 in
2315 in
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)
2579 (
2602 (
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."
2582 ,
2605 ,
2583 D.stack
2606 D.stack
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
2808
2831
2809 FuncArrow row col ->
2832 FuncArrow row col ->
2810− let
2811− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2812− region = toRegion row col
2813− in
2814 case Code.whatIsNext source row col of
2833 case Code.whatIsNext source row col of
2815 Code.Keyword keyword ->
2834 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
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)
2818 (
2841 (
@@ -2825,6 +2848,10 @@ toFuncReport source context func startRow startCol =
2825 )
2848 )
2826
2849
2827 _ ->
2850 _ ->
2851+ let
2852+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2853+ region = toRegion row col
2854+ in
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)
2830 (
2857 (
@@ -2938,7 +2965,7 @@ toPatternReport source context pattern startRow startCol =
2938 Code.Keyword keyword ->
2965 Code.Keyword keyword ->
2939 let
2966 let
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 ->
3080 let
3107 let
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
3083 in
3110 in
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 ->
3146 let
3173 let
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
3149 in
3176 in
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 ->
3265 let
3292 let
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
3268 in
3295 in
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 ->
3406− let
3407− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3408− region = toRegion row col
3409− in
3410 case Code.whatIsNext source row col of
3433 case Code.whatIsNext source row col of
3411 Code.Keyword keyword ->
3434 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
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)
3414 (
3441 (
@@ -3421,6 +3448,10 @@ toTRecordReport source record startRow startCol =
3421 )
3448 )
3422
3449
3423 _ ->
3450 _ ->
3451+ let
3452+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3453+ region = toRegion row col
3454+ in
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)
3426 (
3457 (
@@ -3460,7 +3491,7 @@ toTRecordReport source record startRow startCol =
3460 Code.Keyword keyword ->
3491 Code.Keyword keyword ->
3461 let
3492 let
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
3464 in
3495 in
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 ->
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+ )
3654
3718
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
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+ )
3657
3738
3658 TTupleType tipe row col ->
3739 TTupleType tipe row col ->
3659− error "TODO TTupleType" tipe row col
3740+ toTypeReport source tipe row col
3660
3741
3661 TTupleSpace space row col ->
3742 TTupleSpace space row col ->
3662 toSpaceReport source space row col
3743 toSpaceReport source space row col
3663
3744
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
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+ )
3666
3767
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
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+ )
3669
3790
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
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+ )