unified: add field declarations for statements and members

Part 1 of N of "getting rid of $children" in node-types.yml

Note: in one of the cases the affected node still has the $children
field present. This is because there's some weirdness about recording
multiline comments as class member separators that I did not want to
figure out how to address right now.
This commit is contained in:
Taus
2026-05-08 21:40:53 +00:00
parent 911e59caef
commit 9dddd93460
2 changed files with 15 additions and 13 deletions

View File

@@ -255,11 +255,11 @@ module.exports = grammar({
////////////////////////////////
source_file: ($) =>
seq(
optional($.shebang_line),
optional(field("shebang", $.shebang_line)),
optional(
seq(
$._top_level_statement,
repeat(seq($._semi, $._top_level_statement)),
field("statement", $._top_level_statement),
repeat(seq($._semi, field("statement", $._top_level_statement))),
optional($._semi)
)
)
@@ -1182,8 +1182,8 @@ module.exports = grammar({
prec.left(
// Left precedence is required in switch statements
seq(
$._local_statement,
repeat(seq($._semi, $._local_statement)),
field("statement", $._local_statement),
repeat(seq($._semi, field("statement", $._local_statement))),
optional($._semi)
)
),
@@ -1605,7 +1605,7 @@ module.exports = grammar({
_class_member_separator: ($) => choice($._semi, $.multiline_comment),
_class_member_declarations: ($) =>
seq(
sep1($.type_level_declaration, $._class_member_separator),
sep1(field("member", $.type_level_declaration), $._class_member_separator),
optional($._class_member_separator)
),
_function_value_parameters: ($) =>
@@ -1673,7 +1673,7 @@ module.exports = grammar({
throws_clause: ($) =>
seq($._throws_keyword, "(", field("type", $.unannotated_type), ")"),
enum_class_body: ($) =>
seq("{", repeat(choice($.enum_entry, $.type_level_declaration)), "}"),
seq("{", repeat(field("member", choice($.enum_entry, $.type_level_declaration))), "}"),
enum_entry: ($) =>
seq(
optional($.modifiers),
@@ -1725,7 +1725,7 @@ module.exports = grammar({
protocol_body: ($) =>
seq("{", optional($._protocol_member_declarations), "}"),
_protocol_member_declarations: ($) =>
seq(sep1($.protocol_member_declaration, $._semi), optional($._semi)),
seq(sep1(field("member", $.protocol_member_declaration), $._semi), optional($._semi)),
protocol_member_declaration: ($) =>
choice(
$.protocol_function_declaration,

View File

@@ -166,7 +166,8 @@ named:
target: expression
type: type
class_body:
$children*: [multiline_comment, type_level_declaration]
$children*: multiline_comment
member*: type_level_declaration
class_declaration:
$children*: [attribute, inheritance_modifier, inheritance_specifier, modifiers, ownership_modifier, property_behavior_modifier, type_constraints, type_parameters]
body: [class_body, enum_class_body]
@@ -226,7 +227,7 @@ named:
$children*: [catch_block, statements]
else:
enum_class_body:
$children*: [enum_entry, type_level_declaration]
member*: [enum_entry, type_level_declaration]
enum_entry:
$children?: modifiers
data_contents*: enum_type_parameters
@@ -410,7 +411,7 @@ named:
value*: expression
property_modifier:
protocol_body:
$children*: protocol_member_declaration
member*: protocol_member_declaration
protocol_composition_type:
$children+: unannotated_type
protocol_declaration:
@@ -459,11 +460,12 @@ named:
shebang_line:
simple_identifier:
source_file:
$children*: [do_statement, expression, for_statement, global_declaration, guard_statement, repeat_while_statement, shebang_line, statement_label, throw_keyword, while_statement]
shebang?: shebang_line
statement*: [do_statement, expression, for_statement, global_declaration, guard_statement, repeat_while_statement, statement_label, throw_keyword, while_statement]
special_literal:
statement_label:
statements:
$children+: [control_transfer_statement, do_statement, expression, for_statement, guard_statement, local_declaration, repeat_while_statement, statement_label, while_statement]
statement+: [control_transfer_statement, do_statement, expression, for_statement, guard_statement, local_declaration, repeat_while_statement, statement_label, while_statement]
str_escaped_char:
subscript_declaration:
$children+: [attribute, computed_property, modifiers, parameter, type_constraints, type_parameters]