Skip to content

Commit c0efc52

Browse files
committed
unified: make if-condition nodes named, to stop bleed
Before, the `condition` field of an if statement supposedly could contain things like parentheses and commas, due to bleeding from referenced anonymous nodes. Making the node named makes this issue go away.
1 parent 5c16b0f commit c0efc52

2 files changed

Lines changed: 13 additions & 17 deletions

File tree

unified/extractor/tree-sitter-swift/grammar.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,12 +1035,12 @@ module.exports = grammar({
10351035
PRECS["if"],
10361036
seq(
10371037
"if",
1038-
sep1(field("condition", $._if_condition_sequence_item), ","),
1038+
sep1(field("condition", $.if_condition), ","),
10391039
$._block,
10401040
optional(seq($["else"], $._else_options))
10411041
)
10421042
),
1043-
_if_condition_sequence_item: ($) =>
1043+
if_condition: ($) =>
10441044
choice($._if_let_binding, $._expression, $.availability_condition),
10451045
_if_let_binding: ($) =>
10461046
seq(
@@ -1053,7 +1053,7 @@ module.exports = grammar({
10531053
PRECS["if"],
10541054
seq(
10551055
"guard",
1056-
sep1(field("condition", $._if_condition_sequence_item), ","),
1056+
sep1(field("condition", $.if_condition), ","),
10571057
$["else"],
10581058
$._block
10591059
)
@@ -1237,7 +1237,7 @@ module.exports = grammar({
12371237
PRECS.loop,
12381238
seq(
12391239
"while",
1240-
sep1(field("condition", $._if_condition_sequence_item), ","),
1240+
sep1(field("condition", $.if_condition), ","),
12411241
"{",
12421242
optional($.statements),
12431243
"}"
@@ -1254,7 +1254,7 @@ module.exports = grammar({
12541254
// Make sure we make it to the `while` before assuming this is a parameter pack.
12551255
repeat($._implicit_semi),
12561256
"while",
1257-
sep1(field("condition", $._if_condition_sequence_item), ",")
1257+
sep1(field("condition", $.if_condition), ",")
12581258
)
12591259
),
12601260
control_transfer_statement: ($) =>

unified/extractor/tree-sitter-swift/node-types.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,17 @@ named:
165165
$children*: [mutation_modifier, throws, throws_clause]
166166
guard_statement:
167167
$children+: [else, statements]
168-
bound_identifier*: simple_identifier
169-
condition+: ["(", ")", ",", ".", ":", "=", "?", additive_expression, array_literal, array_type, "as", as_expression, assignment, "async", availability_condition, await_expression, bin_literal, bitwise_operation, boolean_literal, call_expression, "case", check_expression, comparison_expression, conjunction_expression, constructor_expression, diagnostic, dictionary_literal, dictionary_type, directive, disjunction_expression, equality_expression, existential_type, fully_open_range, function_type, hex_literal, if_statement, infix_expression, integer_literal, "is", key_path_expression, key_path_string_expression, lambda_literal, line_string_literal, macro_invocation, metatype, multi_line_string_literal, multiplicative_expression, navigation_expression, "nil", nil_coalescing_expression, oct_literal, opaque_type, open_end_range_expression, open_start_range_expression, optional_chain_marker, optional_type, pattern, playground_literal, postfix_expression, prefix_expression, protocol_composition_type, range_expression, raw_string_literal, real_literal, referenceable_operator, regex_literal, selector_expression, self_expression, simple_identifier, special_literal, super_expression, suppressed_constraint, switch_statement, ternary_expression, try_expression, tuple_expression, tuple_type, type_annotation, type_modifiers, type_pack_expansion, type_parameter_pack, user_type, value_binding_pattern, value_pack_expansion, value_parameter_pack, where_clause, wildcard_pattern]
170-
name*: [array_type, dictionary_type, existential_type, function_type, metatype, opaque_type, optional_type, protocol_composition_type, suppressed_constraint, tuple_type, type_pack_expansion, type_parameter_pack, user_type]
168+
condition+: if_condition
171169
hex_literal:
172170
identifier:
173171
$children+: simple_identifier
172+
if_condition:
173+
$children*: [additive_expression, array_literal, as_expression, assignment, availability_condition, await_expression, bin_literal, bitwise_operation, boolean_literal, call_expression, check_expression, comparison_expression, conjunction_expression, constructor_expression, diagnostic, dictionary_literal, directive, disjunction_expression, equality_expression, fully_open_range, hex_literal, if_statement, infix_expression, integer_literal, key_path_expression, key_path_string_expression, lambda_literal, line_string_literal, macro_invocation, multi_line_string_literal, multiplicative_expression, navigation_expression, nil_coalescing_expression, oct_literal, open_end_range_expression, open_start_range_expression, optional_chain_marker, pattern, playground_literal, postfix_expression, prefix_expression, range_expression, raw_string_literal, real_literal, referenceable_operator, regex_literal, selector_expression, self_expression, simple_identifier, special_literal, super_expression, switch_statement, ternary_expression, try_expression, tuple_expression, type_annotation, type_modifiers, user_type, value_binding_pattern, value_pack_expansion, value_parameter_pack, where_clause, wildcard_pattern]
174+
bound_identifier?: simple_identifier
175+
name?: [array_type, dictionary_type, existential_type, function_type, metatype, opaque_type, optional_type, protocol_composition_type, suppressed_constraint, tuple_type, type_pack_expansion, type_parameter_pack, user_type]
174176
if_statement:
175177
$children*: [else, if_statement, statements]
176-
bound_identifier*: simple_identifier
177-
condition+: ["(", ")", ",", ".", ":", "=", "?", additive_expression, array_literal, array_type, "as", as_expression, assignment, "async", availability_condition, await_expression, bin_literal, bitwise_operation, boolean_literal, call_expression, "case", check_expression, comparison_expression, conjunction_expression, constructor_expression, diagnostic, dictionary_literal, dictionary_type, directive, disjunction_expression, equality_expression, existential_type, fully_open_range, function_type, hex_literal, if_statement, infix_expression, integer_literal, "is", key_path_expression, key_path_string_expression, lambda_literal, line_string_literal, macro_invocation, metatype, multi_line_string_literal, multiplicative_expression, navigation_expression, "nil", nil_coalescing_expression, oct_literal, opaque_type, open_end_range_expression, open_start_range_expression, optional_chain_marker, optional_type, pattern, playground_literal, postfix_expression, prefix_expression, protocol_composition_type, range_expression, raw_string_literal, real_literal, referenceable_operator, regex_literal, selector_expression, self_expression, simple_identifier, special_literal, super_expression, suppressed_constraint, switch_statement, ternary_expression, try_expression, tuple_expression, tuple_type, type_annotation, type_modifiers, type_pack_expansion, type_parameter_pack, user_type, value_binding_pattern, value_pack_expansion, value_parameter_pack, where_clause, wildcard_pattern]
178-
name*: [array_type, dictionary_type, existential_type, function_type, metatype, opaque_type, optional_type, protocol_composition_type, suppressed_constraint, tuple_type, type_pack_expansion, type_parameter_pack, user_type]
178+
condition+: if_condition
179179
import_declaration:
180180
$children+: [identifier, modifiers]
181181
infix_expression:
@@ -346,9 +346,7 @@ named:
346346
regex_literal:
347347
repeat_while_statement:
348348
$children?: statements
349-
bound_identifier*: simple_identifier
350-
condition+: ["(", ")", ",", ".", ":", "=", "?", additive_expression, array_literal, array_type, "as", as_expression, assignment, "async", availability_condition, await_expression, bin_literal, bitwise_operation, boolean_literal, call_expression, "case", check_expression, comparison_expression, conjunction_expression, constructor_expression, diagnostic, dictionary_literal, dictionary_type, directive, disjunction_expression, equality_expression, existential_type, fully_open_range, function_type, hex_literal, if_statement, infix_expression, integer_literal, "is", key_path_expression, key_path_string_expression, lambda_literal, line_string_literal, macro_invocation, metatype, multi_line_string_literal, multiplicative_expression, navigation_expression, "nil", nil_coalescing_expression, oct_literal, opaque_type, open_end_range_expression, open_start_range_expression, optional_chain_marker, optional_type, pattern, playground_literal, postfix_expression, prefix_expression, protocol_composition_type, range_expression, raw_string_literal, real_literal, referenceable_operator, regex_literal, selector_expression, self_expression, simple_identifier, special_literal, super_expression, suppressed_constraint, switch_statement, ternary_expression, try_expression, tuple_expression, tuple_type, type_annotation, type_modifiers, type_pack_expansion, type_parameter_pack, user_type, value_binding_pattern, value_pack_expansion, value_parameter_pack, where_clause, wildcard_pattern]
351-
name*: [array_type, dictionary_type, existential_type, function_type, metatype, opaque_type, optional_type, protocol_composition_type, suppressed_constraint, tuple_type, type_pack_expansion, type_parameter_pack, user_type]
349+
condition+: if_condition
352350
selector_expression:
353351
$children?: [additive_expression, array_literal, as_expression, assignment, await_expression, bin_literal, bitwise_operation, boolean_literal, call_expression, check_expression, comparison_expression, conjunction_expression, constructor_expression, diagnostic, dictionary_literal, directive, disjunction_expression, equality_expression, fully_open_range, hex_literal, if_statement, infix_expression, integer_literal, key_path_expression, key_path_string_expression, lambda_literal, line_string_literal, macro_invocation, multi_line_string_literal, multiplicative_expression, navigation_expression, nil_coalescing_expression, oct_literal, open_end_range_expression, open_start_range_expression, optional_chain_marker, playground_literal, postfix_expression, prefix_expression, range_expression, raw_string_literal, real_literal, referenceable_operator, regex_literal, selector_expression, self_expression, simple_identifier, special_literal, super_expression, switch_statement, ternary_expression, try_expression, tuple_expression, value_pack_expansion, value_parameter_pack]
354352
self_expression:
@@ -452,9 +450,7 @@ named:
452450
where_keyword:
453451
while_statement:
454452
$children?: statements
455-
bound_identifier*: simple_identifier
456-
condition+: ["(", ")", ",", ".", ":", "=", "?", additive_expression, array_literal, array_type, "as", as_expression, assignment, "async", availability_condition, await_expression, bin_literal, bitwise_operation, boolean_literal, call_expression, "case", check_expression, comparison_expression, conjunction_expression, constructor_expression, diagnostic, dictionary_literal, dictionary_type, directive, disjunction_expression, equality_expression, existential_type, fully_open_range, function_type, hex_literal, if_statement, infix_expression, integer_literal, "is", key_path_expression, key_path_string_expression, lambda_literal, line_string_literal, macro_invocation, metatype, multi_line_string_literal, multiplicative_expression, navigation_expression, "nil", nil_coalescing_expression, oct_literal, opaque_type, open_end_range_expression, open_start_range_expression, optional_chain_marker, optional_type, pattern, playground_literal, postfix_expression, prefix_expression, protocol_composition_type, range_expression, raw_string_literal, real_literal, referenceable_operator, regex_literal, selector_expression, self_expression, simple_identifier, special_literal, super_expression, suppressed_constraint, switch_statement, ternary_expression, try_expression, tuple_expression, tuple_type, type_annotation, type_modifiers, type_pack_expansion, type_parameter_pack, user_type, value_binding_pattern, value_pack_expansion, value_parameter_pack, where_clause, wildcard_pattern]
457-
name*: [array_type, dictionary_type, existential_type, function_type, metatype, opaque_type, optional_type, protocol_composition_type, suppressed_constraint, tuple_type, type_pack_expansion, type_parameter_pack, user_type]
453+
condition+: if_condition
458454
wildcard_pattern:
459455
willset_clause:
460456
$children*: [modifiers, simple_identifier, statements]

0 commit comments

Comments
 (0)