Skip to content

Commit 7561691

Browse files
committed
Unified: Consolidate conditional pattern rules
I'm pleasantly surprised that the new syntax for template choices supports having a Rust block as an alternative. We may need to annotate these with the "return type" at some point, in order to make type checking work out, but that can wait.
1 parent 42f0fc9 commit 7561691

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

  • unified/extractor/src/languages/swift

‎unified/extractor/src/languages/swift/swift.rs‎

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -922,13 +922,23 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
922922
),
923923
// A single case item unwraps to its pattern, possibly boxed in conditional_pattern
924924
rule!(
925-
(switchCaseItem
926-
pattern: @p
927-
whereClause: (whereClause condition: @cond))
925+
[
926+
(switchCaseItem
927+
pattern: @pattern
928+
whereClause: (whereClause condition: @condition)?)
929+
(catchItem
930+
pattern: @pattern
931+
whereClause: (whereClause condition: @condition)?)
932+
]
928933
=>
929-
(conditional_pattern pattern: {p} condition: {cond})
934+
[
935+
(conditional_pattern
936+
pattern: {pattern}
937+
condition: {condition})
938+
if { condition.is_some() }
939+
{pattern}
940+
]
930941
),
931-
rule!((switchCaseItem pattern: @p) => pattern { p }),
932942
// A pattern-matching condition (`if case let x = e`, `if case .foo(let x)
933943
// = e`) becomes a `pattern_guard_expr`: the matched pattern and the
934944
// scrutinee value are translated recursively.
@@ -1093,18 +1103,6 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
10931103
body: {body}
10941104
catch_clause: {catches})
10951105
),
1096-
rule!(
1097-
(catchItem
1098-
pattern: @pattern
1099-
whereClause: (whereClause condition: @guard))
1100-
=>
1101-
(conditional_pattern pattern: {pattern} condition: {guard})
1102-
),
1103-
rule!(
1104-
(catchItem pattern: @pattern)
1105-
=>
1106-
pattern {pattern}
1107-
),
11081106
// Catch block with one or more patterns (which have been translated by the catchItem rules)
11091107
rule!(
11101108
(catchClause

0 commit comments

Comments
 (0)