@@ -2284,12 +2284,12 @@ toRecordReport source context record startRow startCol =
2286 RecordField row col ->
2286 RecordField row col ->
2288− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2289− region = toRegion row col
2291 case Code.whatIsNext source row col of
2287 case Code.whatIsNext source row col of
2292 Code.Keyword keyword ->
2288 Code.Keyword keyword ->
2290+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2291+ region = toWiderRegion row col (fromIntegral (length keyword))
2293 Report.Report "RESERVED WORD" region [] $
2293 Report.Report "RESERVED WORD" region [] $
2294 Code.toSnippet source surroundings (Just region)
2294 Code.toSnippet source surroundings (Just region)
@@ -2302,6 +2302,10 @@ toRecordReport source context record startRow startCol =
2306+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2307+ region = toRegion row col
2305 Report.Report "UNFINISHED RECORD" region [] $
2309 Report.Report "UNFINISHED RECORD" region [] $
2306 Code.toSnippet source surroundings (Just region)
2310 Code.toSnippet source surroundings (Just region)
@@ -2443,7 +2447,7 @@ addNoteForRecordError normalRecommendation =
2445 , D.reflow $
2449 , D.reflow $
2446− "Notice that nothing comes directly after a newline. Each line starts with some spaces. I\
2450+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
2447 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
2451 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
2448 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
2452 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -2458,13 +2462,13 @@ addNoteForRecordIndentError normalRecommendation =
2458 "I may be confused by indentation. For example, if you are trying to define\
2462 "I may be confused by indentation. For example, if you are trying to define\
2459 \ a record across multiple lines, I recommend using this format:"
2463 \ a record across multiple lines, I recommend using this format:"
2460 , D.indent 4 $ D.vcat $
2464 , D.indent 4 $ D.vcat $
2461− [ "[ \"Alice\""
2465+ [ "{ name = \"Alice\""
2462− , ", \"Bob\""
2466+ , ", age = 42"
2463− , ", \"Chuck\""
2467+ , ", height = 1.75"
2466 , D.reflow $
2470 , D.reflow $
2467− "Notice that nothing comes directly after a newline. Each line starts with some spaces. I\
2471+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
2468 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
2472 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
2469 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
2473 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
@@ -3399,38 +3403,247 @@ toTRecordReport :: Code.Source -> TRecord -> Row -> Col -> Report.Report
3399toTRecordReport source record startRow startCol =
3403toTRecordReport source record startRow startCol =
3400 case record of
3404 case record of
3401 TRecordOpen row col ->
3405 TRecordOpen row col ->
3402− error "TODO TRecordOpen" row col startRow startCol
3406+ let
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
3411+ Code.Keyword keyword ->
3412+ Report.Report "RESERVED WORD" region [] $
3413+ Code.toSnippet source surroundings (Just region)
3416+ "I just started parsing a record type, but I got stuck on this field name:"
3419+ "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
3420+ \ that is a reserved word. Try using a different name!"
3424+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3425+ Code.toSnippet source surroundings (Just region)
3428+ "I just started parsing a record type, but I got stuck here:"
3431+ ["Record","types","look","like",D.dullyellow "{ name : String, age : Int },"
3432+ ,"so","I","was","expecting","to","see","a","field","name","next."
3404 TRecordEnd row col ->
3436 TRecordEnd row col ->
3405− error "TODO TRecordEnd" row col
3437+ let
3438+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3439+ region = toRegion row col
3441+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3442+ Code.toSnippet source surroundings (Just region)
3445+ "I am partway through parsing a record type, but I got stuck here:"
3449+ ["I","was","expecting","to","see","a","closing","curly","brace","before","this,"
3450+ ,"so","try","adding","a",D.dullyellow "}","and","see","if","that","helps?"
3453+ "When I get stuck like this, it usually means that there is a missing parenthesis\
3454+ \ or bracket somewhere earlier. It could also be a stray keyword or operator."
3407 TRecordField row col ->
3458 TRecordField row col ->
3408− error "TODO TRecordField" row col
3459+ case Code.whatIsNext source row col of
3460+ Code.Keyword keyword ->
3462+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3463+ region = toWiderRegion row col (fromIntegral (length keyword))
3465+ Report.Report "RESERVED WORD" region [] $
3466+ Code.toSnippet source surroundings (Just region)
3469+ "I am partway through parsing a record type, but I got stuck on this field name:"
3472+ "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
3473+ \ that is a reserved word. Try using a different name!"
3478+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3479+ region = toRegion row col
3481+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3482+ Code.toSnippet source surroundings (Just region)
3485+ "I am partway through parsing a record type, but I got stuck after that last comma:"
3487+ addNoteForRecordTypeError $
3489+ "Trailing commas are not allowed in records, so I was expecting to see another\
3490+ \ record field defined next. If you are done defining the record, the fix may\
3491+ \ be to delete that last comma?"
3410 TRecordColon row col ->
3494 TRecordColon row col ->
3411− error "TODO TRecordColon" row col
3495+ let
3496+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3497+ region = toRegion row col
3499+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3500+ Code.toSnippet source surroundings (Just region)
3503+ "I am partway through parsing a record type, but I got stuck here:"
3505+ addNoteForRecordTypeError $
3507+ ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
3508+ ,"a","colon","next.","So","try","putting","an",D.green ":","sign","here?"
3413 TRecordType tipe row col ->
3512 TRecordType tipe row col ->
3414− error "TODO TRecordType" tipe row col
3513+ toTypeReport source tipe row col
3416 TRecordSpace space row col ->
3515 TRecordSpace space row col ->
3417 toSpaceReport source space row col
3516 toSpaceReport source space row col
3419 TRecordIndentOpen row col ->
3518 TRecordIndentOpen row col ->
3420− error "TODO TRecordIndentOpen" row col
3519+ let
3520+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3521+ region = toRegion row col
3523+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3524+ Code.toSnippet source surroundings (Just region)
3527+ "I just saw the opening curly brace of a record type, but then I got stuck here:"
3529+ addNoteForRecordTypeIndentError $
3531+ ["I","am","expecting","a","record","like",D.dullyellow "{ name : String, age : Int }","here."
3532+ ,"Try","defining","some","fields","of","your","own?"
3536+ TRecordIndentEnd row col ->
3538+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3539+ region = toRegion row col
3541+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3542+ Code.toSnippet source surroundings (Just region)
3545+ "I was expecting to see a closing curly brace next:"
3547+ addNoteForRecordTypeIndentError $
3549+ ["Try","putting","an",D.green "}","and","see","if","that","helps?"
3422 TRecordIndentField row col ->
3553 TRecordIndentField row col ->
3423− error "TODO TRecordIndentField" row col
3554+ let
3555+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3556+ region = toRegion row col
3558+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3559+ Code.toSnippet source surroundings (Just region)
3562+ "I am partway through parsing a record type, but I got stuck after that last comma:"
3564+ addNoteForRecordTypeIndentError $
3566+ "Trailing commas are not allowed in record types, so the fix may be to\
3567+ \ delete that last comma? Or maybe you were in the middle of defining\
3568+ \ an additional field?"
3425 TRecordIndentColon row col ->
3571 TRecordIndentColon row col ->
3426− error "TODO TRecordIndentColon" row col
3572+ let
3573+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3574+ region = toRegion row col
3576+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3577+ Code.toSnippet source surroundings (Just region)
3580+ "I am partway through parsing a record type. I just saw a record\
3581+ \ field, so I was expecting to see a colon next:"
3583+ addNoteForRecordTypeIndentError $
3585+ ["Try","putting","an",D.green ":","followed","by","a","type?"
3428 TRecordIndentType row col ->
3589 TRecordIndentType row col ->
3429− error "TODO TRecordIndentType" row col
3590+ let
3591+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3592+ region = toRegion row col
3594+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3595+ Code.toSnippet source surroundings (Just region)
3598+ "I am partway through parsing a record type, and I was expecting to run into a type next:"
3600+ addNoteForRecordTypeIndentError $
3602+ ["Try","putting","something,","like"
3603+ ,D.dullyellow "Int","or",D.dullyellow "String","for","now?"
3431− TRecordIndentEnd row col ->
3432− error "TODO TRecordIndentEnd" row col
3608+addNoteForRecordTypeError :: D.Doc -> D.Doc
3609+addNoteForRecordTypeError normalRecommendation =
3611+ normalRecommendation
3614+ "If you are trying to define a record type across multiple lines, I recommend using this format:"
3615+ , D.indent 4 $ D.vcat $
3616+ [ "{ name : String"
3618+ , ", height : Float"
3622+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
3623+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
3624+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
3628+addNoteForRecordTypeIndentError :: D.Doc -> D.Doc
3629+addNoteForRecordTypeIndentError normalRecommendation =
3631+ normalRecommendation
3634+ "I may be confused by indentation. For example, if you are trying to define\
3635+ \ a record type across multiple lines, I recommend using this format:"
3636+ , D.indent 4 $ D.vcat $
3637+ [ "{ name : String"
3639+ , ", height : Float"
3643+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
3644+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
3645+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
3436toTTupleReport :: Code.Source -> TTuple -> Row -> Col -> Report.Report
3649toTTupleReport :: Code.Source -> TTuple -> Row -> Col -> Report.Report