@@ -3284,51 +3284,6 @@ fn State::parse_lex_simple_atom_pattern(self : State) -> @syntax.LexPattern {
32843284 }
32853285}
32863286
3287- ///|
3288- fn State ::parse_multi_pattern_case (self : Self ) -> @syntax .MultiArgCase {
3289- if self .mode is Panic (loc ~, ..) {
3290- return {
3291- patterns : @list .new (),
3292- guard_ : None ,
3293- body : Hole (loc ~, kind = Synthesized ),
3294- }
3295- }
3296- fn parse_patterns (state : State ) -> Array [@syntax .Pattern ] {
3297- state .with_follow (follow_set = [TK_FAT_ARROW , TK_IF ], fn (state ) {
3298- state .sepby1 (delim = TK_COMMA , State ::parse_pattern)
3299- })
3300- }
3301-
3302- let patterns = self .with_syncs ([TK_FAT_ARROW , TK_IF ], parse_patterns )
3303- |> @list .from_array
3304- let guard_ = match self .peek_token () {
3305- IF => {
3306- self .skip ()
3307- let expr = match self .peek_token () {
3308- // an error production to handle: `pattern if invalid-infix-expr => action`
3309- IF
3310- | MATCH
3311- | LOOP
3312- | WHILE
3313- | FOR
3314- | TRY
3315- | LET
3316- | GUARD
3317- | BREAK
3318- | RETURN
3319- | CONTINUE =>
3320- self .handle_unexpected_expr_or_statement (context = "pattern guard" )
3321- _ => self .parse_infix_expr (parsed = None )
3322- }
3323- Some (expr )
3324- }
3325- _ => None
3326- }
3327- self .expect_token (TK_FAT_ARROW )
3328- let body = self .parse_expr_stmt ()
3329- { patterns , guard_ , body }
3330- }
3331-
33323287///|
33333288fn State ::parse_tuple_or_constraint (self : Self ) -> @syntax .Expr {
33343289 if self .mode is Panic (loc ~, ..) {
@@ -3397,6 +3352,7 @@ fn State::handle_lparen(self : Self) -> @syntax.Expr {
33973352 let handle_expr = fn (expr ) { self .parse_simple_try_expr (parsed = Some (expr )) }
33983353 match (self .peek_token (), expr_or_binders ) {
33993354 (FAT_ARROW , _ ) => {
3355+ let params_loc = self .loc_start_with (spos )
34003356 self .skip ()
34013357 fn as_binder (expr : @syntax .Expr ) -> @syntax .ArrowFnParam {
34023358 match expr {
@@ -3422,7 +3378,10 @@ fn State::handle_lparen(self : Self) -> @syntax.Expr {
34223378 |> @list .from_array
34233379 let body = self .parse_expr_stmt_no_break_continue_return ()
34243380 let loc = self .loc_start_with (spos )
3425- Function (loc ~, func = @syntax .make_arrow_fn (loc ~, parameters , body ))
3381+ Function (
3382+ loc ~,
3383+ func = @syntax .make_arrow_fn (params_loc ~, loc ~, parameters , body ),
3384+ )
34263385 }
34273386 (_ , []) => {
34283387 let loc = self .loc_start_with (spos )
@@ -3516,12 +3475,14 @@ fn State::parse_expr(self : Self) -> @syntax.Expr {
35163475 }
35173476 _ => panic ()
35183477 }
3478+ let params_loc = self .loc_start_with (spos )
35193479 self .expect_token (TK_FAT_ARROW )
35203480 let body = self .parse_expr_stmt_no_break_continue_return ()
35213481 let loc = self .loc_start_with (spos )
35223482 let func = @syntax .make_arrow_fn (
35233483 @list .from_array ([(p , None )]),
35243484 body ,
3485+ params_loc ~,
35253486 loc ~,
35263487 )
35273488 Function (loc ~, func ~)
@@ -4009,17 +3970,17 @@ fn State::parse_func(
40093970 is_async ~ : Location? ,
40103971) -> @syntax .Func {
40113972 if self .mode is Panic (loc ~, ..) {
4012- return @syntax .Lambda (
4013- parameters = @list .new (),
4014- params_loc = loc ,
4015- body = @syntax .Hole (loc ~, kind = Synthesized ),
4016- return_type = None ,
4017- error_type = @syntax .NoErrorType ,
4018- kind = Lambda ,
4019- has_error ~ ,
4020- is_async ~ ,
4021- loc ~ ,
4022- )
3973+ return @syntax .Func ::{
3974+ parameters : @list .new (),
3975+ params_loc : loc ,
3976+ body : @syntax .Hole (loc ~, kind = Synthesized ),
3977+ return_type : None ,
3978+ error_type : @syntax .NoErrorType ,
3979+ kind : Lambda ,
3980+ has_error ,
3981+ is_async ,
3982+ loc ,
3983+ }
40233984 }
40243985 match self .peek_token () {
40253986 LPAREN => {
@@ -4036,42 +3997,35 @@ fn State::parse_func(
40363997 self .pop_sync (TK_LBRACE )
40373998 let block = self .parse_block_expr ()
40383999 let func_loc = @syntax .no_location
4039- @syntax .Lambda ( // Will be set by caller
4040- parameters = @list .from_array (params ),
4041- params_loc ~,
4042- body = block ,
4043- return_type ~,
4044- error_type ~,
4045- kind = Lambda ,
4046- has_error ~,
4047- is_async ~,
4048- loc = func_loc ,
4049- )
4050- }
4051- LBRACE => {
4052- let loc_start = self .peek_spos ()
4053- let fn_loc = @syntax .no_location // Will be set by caller
4054- let cases = self .parse_match_fn_body ()
4055- let loc = self .loc_start_with (loc_start )
4056- @syntax .Match (cases ~, has_error ~, is_async ~, fn_loc ~, loc ~)
4000+ @syntax .Func ::{ // Will be set by caller
4001+ parameters : @list .from_array (params ),
4002+ params_loc ,
4003+ body : block ,
4004+ return_type ,
4005+ error_type ,
4006+ kind : Lambda ,
4007+ has_error ,
4008+ is_async ,
4009+ loc : func_loc ,
4010+ }
40574011 }
40584012 other => {
40594013 self .report_error ({
40604014 loc : self .peek_location (),
40614015 msg : "Failed to parse func: expected '(' or '{', got \{ other } " ,
40624016 })
40634017 let loc = self .panic ()
4064- @syntax .Lambda (
4065- parameters = @list .new (),
4066- params_loc = loc ,
4067- body = @syntax .Hole (loc ~, kind = Synthesized ),
4068- return_type = None ,
4069- error_type = @syntax .NoErrorType ,
4070- kind = Lambda ,
4071- has_error ~ ,
4072- is_async ~ ,
4073- loc ~ ,
4074- )
4018+ @syntax .Func ::{
4019+ parameters : @list .new (),
4020+ params_loc : loc ,
4021+ body : @syntax .Hole (loc ~, kind = Synthesized ),
4022+ return_type : None ,
4023+ error_type : @syntax .NoErrorType ,
4024+ kind : Lambda ,
4025+ has_error ,
4026+ is_async ,
4027+ loc ,
4028+ }
40754029 }
40764030 }
40774031}
@@ -4667,17 +4621,17 @@ fn State::parse_block_expr(self : Self) -> @syntax.Expr {
46674621///|
46684622fn State ::parse_letand_func (self : Self ) -> @syntax .Func {
46694623 if self .mode is Panic (loc ~, ..) {
4670- return Lambda (
4671- parameters = @list .new (),
4672- params_loc = loc ,
4673- body = Hole (loc ~, kind = Synthesized ),
4674- return_type = None ,
4675- error_type = NoErrorType ,
4676- kind = Lambda ,
4677- has_error = None ,
4678- is_async = None ,
4679- loc ~ ,
4680- )
4624+ return @syntax . Func ::{
4625+ parameters : @list .new (),
4626+ params_loc : loc ,
4627+ body : Hole (loc ~, kind = Synthesized ),
4628+ return_type : None ,
4629+ error_type : NoErrorType ,
4630+ kind : Lambda ,
4631+ has_error : None ,
4632+ is_async : None ,
4633+ loc ,
4634+ }
46814635 }
46824636 fn parse_arrow_fn_param () -> @syntax .ArrowFnParam {
46834637 if self .peek_token () is UNDERSCORE {
@@ -4703,17 +4657,29 @@ fn State::parse_letand_func(self : Self) -> @syntax.Func {
47034657 (param , ty_opt )
47044658 },
47054659 )
4660+ let params_loc = self .loc_start_with (spos )
47064661 self .expect_token (TK_FAT_ARROW )
47074662 let body = self .parse_expr_stmt_no_break_continue_return ()
47084663 let loc = self .loc_start_with (spos )
4709- @syntax .make_arrow_fn (@list .from_array (parameters ), body , loc ~)
4664+ @syntax .make_arrow_fn (
4665+ @list .from_array (parameters ),
4666+ body ,
4667+ params_loc ~,
4668+ loc ~,
4669+ )
47104670 }
47114671 LIDENT (_ ) | UNDERSCORE => {
47124672 let param = parse_arrow_fn_param ()
4673+ let params_loc = self .loc_start_with (spos )
47134674 self .expect_token (TK_FAT_ARROW )
47144675 let body = self .parse_expr_stmt_no_break_continue_return ()
47154676 let loc = self .loc_start_with (spos )
4716- @syntax .make_arrow_fn (@list .from_array ([(param , None )]), body , loc ~)
4677+ @syntax .make_arrow_fn (
4678+ @list .from_array ([(param , None )]),
4679+ body ,
4680+ params_loc ~,
4681+ loc ~,
4682+ )
47174683 }
47184684 _ => {
47194685 let is_async = if self .peek_token () is ASYNC {
@@ -4995,17 +4961,6 @@ fn State::parse_expr_stmt(self : Self) -> @syntax.Expr {
49954961 }
49964962}
49974963
4998- ///|
4999- fn State ::parse_match_fn_body (self : Self ) -> @list .List [@syntax .MultiArgCase ] {
5000- self .surround_series (
5001- left = TK_LBRACE ,
5002- right = TK_RBRACE ,
5003- delim = TK_SEMI ,
5004- State ::parse_multi_pattern_case,
5005- )
5006- |> @list .from_array
5007- }
5008-
50094964///|
50104965fn State ::parse_error_type (self : Self ) -> @syntax .Type {
50114966 if self .mode is Panic (loc ~, ..) {
0 commit comments