on master help sign in
Fill in error messages for pattern lists
commitfbbc543ad38eef12633c4dd0942a4bcc31eeb4f5 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 16 May 2019, 15:30 (7 years ago) parent374bf9a
1 file changed+94−6
compiler/src/Reporting/Error/Syntax.hs+94−6
compiler/src/Reporting/Error/Syntax.hs+94−6
@@ -3233,7 +3233,7 @@ toPTupleReport source context tuple startRow startCol =
32333233 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
32343234 region = toRegion row col
32353235 in
3236− Report.Report "UNFINISHED TUPLE" region [] $
3236+ Report.Report "UNFINISHED TUPLE PATTERN" region [] $
32373237 Code.toSnippet source surroundings (Just region) $
32383238 (
32393239 D.reflow $
@@ -3256,10 +3256,49 @@ toPListReport :: Code.Source -> PContext -> PList -> Row -> Col -> Report.Report
32563256toPListReport source context list startRow startCol =
32573257 case list of
32583258 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+ )
32603288
32613289 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+ )
32633302
32643303 PListExpr pattern row col ->
32653304 toPatternReport source context pattern row col
@@ -3268,13 +3307,62 @@ toPListReport source context list startRow startCol =
32683307 toSpaceReport source space row col
32693308
32703309 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+ )
32723327
32733328 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+ )
32753346
32763347 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+ )
32783366
32793367
32803368