@@ -129,13 +129,6 @@ fn member_chain(
129129 result
130130}
131131
132- /// Compound-assignment operator spellings (`+=`, `<<=`, ...). Used to tell a
133- /// compound assignment from an ordinary binary application, both of which
134- /// arrive as a `binaryOperator`-based `infixOperatorExpr`.
135- const COMPOUND_ASSIGN_OPS : & [ & str ] = & [
136- "+=" , "-=" , "*=" , "/=" , "%=" , "<<=" , ">>=" , "&=" , "|=" , "^=" , "&+=" , "&-=" , "&*=" ,
137- ] ;
138-
139132fn translation_rules ( ) -> Vec < Rule < SwiftContext > > {
140133 vec ! [
141134 // ---- Top-level ----
@@ -243,29 +236,21 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
243236 // operator leaf. Used by `infixOperatorExpr` (folded) and `sequenceExpr`
244237 // (unresolved).
245238 rule!( ( binaryOperatorExpr operator: @op) => ( infix_operator #{ op} ) ) ,
246- // Compound assignment (`x += y`) vs. an ordinary binary application
247- // (`a + b`): both are `binaryOperator`-based `infixOperatorExpr`s,
248- // distinguishable only by the operator's spelling. The query engine
249- // can't match on token text, so a small Rust block reads the spelling
250- // and routes to `compound_assign_expr` or `binary_expr`. The operator
251- // is captured raw (`@@op`) to read its spelling.
239+ // A `binaryOperator`-based `infixOperatorExpr` represents both ordinary
240+ // binary applications (`a + b`) and compound assignments (`x += y`).
241+ // Both have the same target AST shape; the QL library distinguishes
242+ // assignments by the operator spelling.
252243 rule!(
253244 ( infixOperatorExpr leftOperand: @l operator: ( binaryOperatorExpr) @@op rightOperand: @r)
254245 =>
255- expr {
256- if COMPOUND_ASSIGN_OPS . contains( & ctx. source_text( op) . as_str( ) ) {
257- tree!( ( compound_assign_expr target: { l} operator: ( infix_operator #{ op} ) value: { r} ) )
258- } else {
259- tree!( ( binary_expr left: { l} operator: ( infix_operator #{ op} ) right: { r} ) )
260- }
261- }
246+ ( binary_expr left: { l} operator: ( infix_operator #{ op} ) right: { r} )
262247 ) ,
263- // Plain assignment (`x = y`). In a folded chain the `=` is an
264- // `assignmentExpr` node (distinct from other operators), matched by kind .
248+ // Plain assignment (`x = y`). In a folded chain the `=` is represented
249+ // by an `assignmentExpr` node rather than a `binaryOperatorExpr` .
265250 rule!(
266- ( infixOperatorExpr leftOperand: @l operator: ( assignmentExpr) rightOperand: @r)
251+ ( infixOperatorExpr leftOperand: @l operator: ( assignmentExpr) @op rightOperand: @r)
267252 =>
268- ( assign_expr target : { l} value : { r} )
253+ ( binary_expr left : { l} operator : ( infix_operator # { op } ) right : { r} )
269254 ) ,
270255 // In an unresolved `sequenceExpr` (below) the operator positions are not
271256 // only `binaryOperatorExpr`s: a plain assignment (`=`), an `as`/`is` cast
0 commit comments