@@ -979,7 +979,7 @@ module.exports = grammar({
979979 seq (
980980 choice ( "{" , "^{" ) ,
981981 optional ( $ . _lambda_type_declaration ) ,
982- field ( "body" , optional ( $ . statements ) ) ,
982+ optional ( $ . _statements ) ,
983983 "}"
984984 )
985985 ) ,
@@ -1041,14 +1041,14 @@ module.exports = grammar({
10411041 ) ,
10421042 self_expression : ( $ ) => "self" ,
10431043 super_expression : ( $ ) => seq ( "super" ) ,
1044- _else_options : ( $ ) => choice ( $ . _block , field ( "else_branch" , $ . if_statement ) ) ,
1044+ _else_options : ( $ ) => choice ( field ( "else_branch" , $ . block ) , field ( "else_branch" , $ . if_statement ) ) ,
10451045 if_statement : ( $ ) =>
10461046 prec . right (
10471047 PRECS [ "if" ] ,
10481048 seq (
10491049 "if" ,
10501050 sep1 ( field ( "condition" , $ . if_condition ) , "," ) ,
1051- $ . _block ,
1051+ field ( "body" , $ . block ) ,
10521052 optional ( seq ( field ( "else_keyword" , $ [ "else" ] ) , $ . _else_options ) )
10531053 )
10541054 ) ,
@@ -1067,7 +1067,7 @@ module.exports = grammar({
10671067 "guard" ,
10681068 sep1 ( field ( "condition" , $ . if_condition ) , "," ) ,
10691069 field ( "else_keyword" , $ [ "else" ] ) ,
1070- $ . _block
1070+ field ( "body" , $ . block )
10711071 )
10721072 ) ,
10731073 switch_statement : ( $ ) =>
@@ -1094,18 +1094,18 @@ module.exports = grammar({
10941094 field ( "default" , $ . default_keyword )
10951095 ) ,
10961096 ":" ,
1097- field ( "body" , $ . statements ) ,
1097+ $ . _statements ,
10981098 optional ( "fallthrough" )
10991099 ) ,
11001100 switch_pattern : ( $ ) => field ( "pattern" , alias ( $ . _binding_pattern_with_expr , $ . pattern ) ) ,
11011101 do_statement : ( $ ) =>
1102- prec . right ( PRECS [ "do" ] , seq ( "do" , $ . _block , repeat ( field ( "catch" , $ . catch_block ) ) ) ) ,
1102+ prec . right ( PRECS [ "do" ] , seq ( "do" , field ( "body" , $ . block ) , repeat ( field ( "catch" , $ . catch_block ) ) ) ) ,
11031103 catch_block : ( $ ) =>
11041104 seq (
11051105 field ( "keyword" , $ . catch_keyword ) ,
11061106 field ( "error" , optional ( alias ( $ . _binding_pattern_no_expr , $ . pattern ) ) ) ,
11071107 field ( "where" , optional ( $ . where_clause ) ) ,
1108- $ . _block
1108+ field ( "body" , $ . block )
11091109 ) ,
11101110 where_clause : ( $ ) => prec . left ( seq ( field ( "keyword" , $ . where_keyword ) , field ( "expr" , $ . expression ) ) ) ,
11111111 key_path_expression : ( $ ) =>
@@ -1181,7 +1181,7 @@ module.exports = grammar({
11811181 ////////////////////////////////
11821182 // Statements - https://docs.swift.org/swift-book/ReferenceManual/Statements.html
11831183 ////////////////////////////////
1184- statements : ( $ ) =>
1184+ _statements : ( $ ) =>
11851185 prec . left (
11861186 // Left precedence is required in switch statements
11871187 seq (
@@ -1204,7 +1204,7 @@ module.exports = grammar({
12041204 $ . _labeled_statement ,
12051205 $ . _throw_statement
12061206 ) ,
1207- _block : ( $ ) => prec ( PRECS . block , seq ( "{" , field ( "body" , optional ( $ . statements ) ) , "}" ) ) ,
1207+ block : ( $ ) => prec ( PRECS . block , seq ( "{" , optional ( $ . _statements ) , "}" ) ) ,
12081208 _labeled_statement : ( $ ) =>
12091209 seq (
12101210 optional ( $ . statement_label ) ,
@@ -1231,7 +1231,7 @@ module.exports = grammar({
12311231 "in" ,
12321232 field ( "collection" , $ . _for_statement_collection ) ,
12331233 field ( "where" , optional ( $ . where_clause ) ) ,
1234- $ . _block
1234+ field ( "body" , $ . block )
12351235 )
12361236 ) ,
12371237 _for_statement_collection : ( $ ) =>
@@ -1248,19 +1248,15 @@ module.exports = grammar({
12481248 seq (
12491249 "while" ,
12501250 sep1 ( field ( "condition" , $ . if_condition ) , "," ) ,
1251- "{" ,
1252- field ( "body" , optional ( $ . statements ) ) ,
1253- "}"
1251+ field ( "body" , $ . block )
12541252 )
12551253 ) ,
12561254 repeat_while_statement : ( $ ) =>
12571255 prec (
12581256 PRECS . loop ,
12591257 seq (
12601258 "repeat" ,
1261- "{" ,
1262- field ( "body" , optional ( $ . statements ) ) ,
1263- "}" ,
1259+ field ( "body" , $ . block ) ,
12641260 // Make sure we make it to the `while` before assuming this is a parameter pack.
12651261 repeat ( $ . _implicit_semi ) ,
12661262 "while" ,
@@ -1443,14 +1439,14 @@ module.exports = grammar({
14431439 field ( "modifiers" , optional ( $ . modifiers ) ) ,
14441440 "willSet" ,
14451441 optional ( seq ( "(" , field ( "parameter" , $ . simple_identifier ) , ")" ) ) ,
1446- $ . _block
1442+ field ( "body" , $ . block )
14471443 ) ,
14481444 didset_clause : ( $ ) =>
14491445 seq (
14501446 field ( "modifiers" , optional ( $ . modifiers ) ) ,
14511447 "didSet" ,
14521448 optional ( seq ( "(" , field ( "parameter" , $ . simple_identifier ) , ")" ) ) ,
1453- $ . _block
1449+ field ( "body" , $ . block )
14541450 ) ,
14551451 typealias_declaration : ( $ ) =>
14561452 seq ( field ( "modifiers" , optional ( $ . modifiers ) ) , $ . _modifierless_typealias_declaration ) ,
@@ -1464,13 +1460,13 @@ module.exports = grammar({
14641460 ) ,
14651461 function_declaration : ( $ ) =>
14661462 prec . right (
1467- seq ( $ . _bodyless_function_declaration , field ( "body" , $ . function_body ) )
1463+ seq ( $ . _bodyless_function_declaration , field ( "body" , $ . block ) )
14681464 ) ,
14691465 _modifierless_function_declaration : ( $ ) =>
14701466 prec . right (
14711467 seq (
14721468 $ . _modifierless_function_declaration_no_body ,
1473- field ( "body" , $ . function_body )
1469+ field ( "body" , $ . block )
14741470 )
14751471 ) ,
14761472 _bodyless_function_declaration : ( $ ) =>
@@ -1496,7 +1492,6 @@ module.exports = grammar({
14961492 field ( "type_constraints" , optional ( $ . type_constraints ) )
14971493 )
14981494 ) ,
1499- function_body : ( $ ) => $ . _block ,
15001495 macro_declaration : ( $ ) =>
15011496 seq (
15021497 $ . _macro_head ,
@@ -1742,7 +1737,7 @@ module.exports = grammar({
17421737 protocol_function_declaration : ( $ ) =>
17431738 seq (
17441739 $ . _bodyless_function_declaration ,
1745- optional ( field ( "body" , $ . function_body ) )
1740+ optional ( field ( "body" , $ . block ) )
17461741 ) ,
17471742 init_declaration : ( $ ) =>
17481743 prec . right (
@@ -1756,12 +1751,12 @@ module.exports = grammar({
17561751 field ( "async" , optional ( $ . _async_keyword ) ) ,
17571752 field ( "throws" , optional ( choice ( $ . throws_clause , $ . throws ) ) ) ,
17581753 field ( "type_constraints" , optional ( $ . type_constraints ) ) ,
1759- optional ( field ( "body" , $ . function_body ) )
1754+ optional ( field ( "body" , $ . block ) )
17601755 )
17611756 ) ,
17621757 deinit_declaration : ( $ ) =>
17631758 prec . right (
1764- seq ( field ( "modifiers" , optional ( $ . modifiers ) ) , "deinit" , field ( "body" , $ . function_body ) )
1759+ seq ( field ( "modifiers" , optional ( $ . modifiers ) ) , "deinit" , field ( "body" , $ . block ) )
17651760 ) ,
17661761 subscript_declaration : ( $ ) =>
17671762 prec . right (
@@ -1784,23 +1779,23 @@ module.exports = grammar({
17841779 seq (
17851780 "{" ,
17861781 choice (
1787- field ( "body" , optional ( $ . statements ) ) ,
1782+ optional ( $ . _statements ) ,
17881783 repeat (
17891784 field ( "accessor" , choice ( $ . computed_getter , $ . computed_setter , $ . computed_modify ) )
17901785 )
17911786 ) ,
17921787 "}"
17931788 ) ,
17941789 computed_getter : ( $ ) =>
1795- seq ( repeat ( field ( "attribute" , $ . attribute ) ) , field ( "specifier" , $ . getter_specifier ) , optional ( $ . _block ) ) ,
1790+ seq ( repeat ( field ( "attribute" , $ . attribute ) ) , field ( "specifier" , $ . getter_specifier ) , optional ( field ( "body" , $ . block ) ) ) ,
17961791 computed_modify : ( $ ) =>
1797- seq ( repeat ( field ( "attribute" , $ . attribute ) ) , field ( "specifier" , $ . modify_specifier ) , optional ( $ . _block ) ) ,
1792+ seq ( repeat ( field ( "attribute" , $ . attribute ) ) , field ( "specifier" , $ . modify_specifier ) , optional ( field ( "body" , $ . block ) ) ) ,
17981793 computed_setter : ( $ ) =>
17991794 seq (
18001795 repeat ( field ( "attribute" , $ . attribute ) ) ,
18011796 field ( "specifier" , $ . setter_specifier ) ,
18021797 optional ( seq ( "(" , field ( "parameter" , $ . simple_identifier ) , ")" ) ) ,
1803- optional ( $ . _block )
1798+ optional ( field ( "body" , $ . block ) )
18041799 ) ,
18051800 getter_specifier : ( $ ) =>
18061801 seq ( field ( "mutation" , optional ( $ . mutation_modifier ) ) , "get" , optional ( $ . _getter_effects ) ) ,
0 commit comments