on master help sign in
Fill in error messages for pattern lists
fbbc543Evan Czaplicki
compiler/src/Reporting/Error/Syntax.hs+94−6
@@ -3233,7 +3233,7 @@ toPTupleReport source context tuple startRow startCol =
3233 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3233 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3234 region = toRegion row col
3234 region = toRegion row col
3235 in
3235 in
3236− Report.Report "UNFINISHED TUPLE" region [] $
3236+ Report.Report "UNFINISHED TUPLE PATTERN" region [] $
3237 Code.toSnippet source surroundings (Just region) $
3237 Code.toSnippet source surroundings (Just region) $
3238 (
3238 (
3239 D.reflow $
3239 D.reflow $
@@ -3256,10 +3256,49 @@ toPListReport :: Code.Source -> PContext -> PList -> Row -> Col -> Report.Report
3256toPListReport source context list startRow startCol =
3256toPListReport source context list startRow startCol =
3257 case list of
3257 case list of
3258 PListOpen row col ->
3258 PListOpen row col ->
3259− error "TODO PListOpen" row col startRow startCol
3259+ case Code.whatIsNext source row col of
3260+ Code.Keyword keyword ->
3261+ let
3262+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3263+ region = toWiderRegion row col (fromIntegral (length keyword))
3264+ in
3265+ Report.Report "RESERVED WORD" region [] $
3266+ Code.toSnippet source surroundings (Just region)
3267+ (
3268+ D.reflow $
3269+ "It looks like you are trying to use `" ++ keyword ++ "` to name an element of a list:"
3270+ ,
3271+ D.reflow $
3272+ "This is a reserved word though! Try using some other name?"
3273+ )
3274+
3275+ _ ->
3276+ let
3277+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3278+ region = toRegion row col
3279+ in
3280+ Report.Report "UNFINISHED LIST PATTERN" region [] $
3281+ Code.toSnippet source surroundings (Just region) $
3282+ (
3283+ D.reflow $
3284+ "I just saw an open square bracket, but then I got stuck here:"
3285+ ,
3286+ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
3287+ )
3260
3288
3261 PListEnd row col ->
3289 PListEnd row col ->
3262− error "TODO PListEnd" row col
3290+ let
3291+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3292+ region = toRegion row col
3293+ in
3294+ Report.Report "UNFINISHED LIST PATTERN" region [] $
3295+ Code.toSnippet source surroundings (Just region) $
3296+ (
3297+ D.reflow $
3298+ "I was expecting a closing square bracket to end this list pattern:"
3299+ ,
3300+ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
3301+ )
3263
3302
3264 PListExpr pattern row col ->
3303 PListExpr pattern row col ->
3265 toPatternReport source context pattern row col
3304 toPatternReport source context pattern row col
@@ -3268,13 +3307,62 @@ toPListReport source context list startRow startCol =
3268 toSpaceReport source space row col
3307 toSpaceReport source space row col
3269
3308
3270 PListIndentOpen row col ->
3309 PListIndentOpen row col ->
3271− error "TODO PListIndentOpen" row col
3310+ let
3311+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3312+ region = toRegion row col
3313+ in
3314+ Report.Report "UNFINISHED LIST PATTERN" region [] $
3315+ Code.toSnippet source surroundings (Just region) $
3316+ (
3317+ D.reflow $
3318+ "I just saw an open square bracket, but then I got stuck here:"
3319+ ,
3320+ D.stack
3321+ [ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
3322+ , D.toSimpleNote $
3323+ "I can get confused by indentation in cases like this, so\
3324+ \ maybe there is something next, but it is not indented enough?"
3325+ ]
3326+ )
3272
3327
3273 PListIndentEnd row col ->
3328 PListIndentEnd row col ->
3274− error "TODO PListIndentEnd" row col
3329+ let
3330+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3331+ region = toRegion row col
3332+ in
3333+ Report.Report "UNFINISHED LIST PATTERN" region [] $
3334+ Code.toSnippet source surroundings (Just region) $
3335+ (
3336+ D.reflow $
3337+ "I was expecting a closing square bracket to end this list pattern:"
3338+ ,
3339+ D.stack
3340+ [ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
3341+ , D.toSimpleNote $
3342+ "I can get confused by indentation in cases like this, so\
3343+ \ maybe you have a closing square bracket but it is not indented enough?"
3344+ ]
3345+ )
3275
3346
3276 PListIndentExpr row col ->
3347 PListIndentExpr row col ->
3277− error "TODO PListIndentExpr" row col
3348+ let
3349+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3350+ region = toRegion row col
3351+ in
3352+ Report.Report "UNFINISHED LIST PATTERN" region [] $
3353+ Code.toSnippet source surroundings (Just region) $
3354+ (
3355+ D.reflow $
3356+ "I am partway through parsing a list pattern, but I got stuck here:"
3357+ ,
3358+ D.stack
3359+ [ D.reflow $
3360+ "I was expecting to see another pattern next. Maybe a variable name."
3361+ , D.toSimpleNote $
3362+ "I can get confused by indentation in cases like this, so\
3363+ \ maybe there is more to this pattern but it is not indented enough?"
3364+ ]
3365+ )
3278
3366
3279
3367
3280
3368