|
139 | 139 | (define-refactoring-rule id:id |
140 | 140 | #:description description |
141 | 141 | (~optional (~seq #:uses-universal-tagged-syntax? uses-universal-tagged-syntax?)) |
| 142 | + (~optional (~seq #:analyzers analyzers)) |
142 | 143 | parse-option:syntax-parse-option ... |
143 | 144 | pattern |
144 | 145 | pattern-directive:syntax-parse-pattern-directive ... |
145 | 146 | replacement) |
146 | 147 | #:declare description (expr/c #'string?) |
| 148 | + #:declare analyzers (expr/c #'(sequence/c expansion-analyzer?)) |
147 | 149 |
|
148 | 150 | #:attr partial-match-log-statement |
149 | 151 | (and (not (empty? (attribute pattern-directive))) |
|
159 | 161 | #:name 'id |
160 | 162 | #:description (string->immutable-string description.c) |
161 | 163 | #:uses-universal-tagged-syntax? (~? uses-universal-tagged-syntax? #false) |
162 | | - #:analyzers (set identifier-usage-analyzer |
163 | | - ignored-result-values-analyzer |
164 | | - variable-mutability-analyzer) |
| 164 | + #:analyzers (for/set ([analyzer (~? analyzers.c '())]) analyzer) |
165 | 165 | #:transformer |
166 | 166 | (λ (stx) |
167 | 167 | (syntax-parse stx |
|
175 | 175 | (define-syntax-parse-rule |
176 | 176 | (define-definition-context-refactoring-rule id:id |
177 | 177 | #:description (~var description (expr/c #'string?)) |
| 178 | + (~optional (~seq #:analyzers (~var analyzers (expr/c #'(sequence/c expansion-analyzer?))))) |
178 | 179 | parse-option:syntax-parse-option ... |
179 | 180 | splicing-pattern |
180 | 181 | pattern-directive:syntax-parse-pattern-directive ... |
|
227 | 228 |
|
228 | 229 | (define-refactoring-rule id |
229 | 230 | #:description description |
| 231 | + (~? (~@ #:analyzers analyzers)) |
230 | 232 | (~var expression expression-matching-id) |
231 | 233 | expression.refactored))) |
232 | 234 |
|
|
275 | 277 |
|
276 | 278 | (module+ test |
277 | 279 | (require rackunit |
278 | | - resyntax/private/analyzer) |
| 280 | + resyntax/private/analyzer |
| 281 | + resyntax/private/syntax-property-bundle) |
279 | 282 |
|
280 | 283 | (test-case "refactoring-rule stores analyzers" |
281 | 284 | (define-refactoring-rule test-rule |
|
285 | 288 |
|
286 | 289 | (check-true (refactoring-rule? test-rule)) |
287 | 290 | (check-true (set? (refactoring-rule-analyzers test-rule))) |
288 | | - (check-equal? (set-count (refactoring-rule-analyzers test-rule)) 3) |
289 | | - (check-true (for/and ([analyzer (in-set (refactoring-rule-analyzers test-rule))]) |
290 | | - (expansion-analyzer? analyzer)))) |
| 291 | + ;; Without #:analyzers, should have empty set (breaking change from previous behavior |
| 292 | + ;; where rules had 3 default analyzers - identifier-usage, ignored-result-values, and |
| 293 | + ;; variable-mutability analyzers) |
| 294 | + (check-equal? (set-count (refactoring-rule-analyzers test-rule)) 0)) |
| 295 | + |
| 296 | + (test-case "refactoring-rule with explicit analyzers" |
| 297 | + (define test-analyzer (make-expansion-analyzer (λ (stx) (syntax-property-bundle)) #:name 'test)) |
| 298 | + (define-refactoring-rule test-rule-with-analyzers |
| 299 | + #:description "test rule with analyzers" |
| 300 | + #:analyzers (list test-analyzer) |
| 301 | + pattern |
| 302 | + replacement) |
| 303 | + |
| 304 | + (check-true (refactoring-rule? test-rule-with-analyzers)) |
| 305 | + (check-equal? (set-count (refactoring-rule-analyzers test-rule-with-analyzers)) 1) |
| 306 | + (check-true (set-member? (refactoring-rule-analyzers test-rule-with-analyzers) test-analyzer))) |
291 | 307 |
|
292 | 308 | (test-case "refactoring-suite combines analyzers from rules" |
| 309 | + (define analyzer1 (make-expansion-analyzer (λ (stx) (syntax-property-bundle)) #:name 'analyzer1)) |
| 310 | + (define analyzer2 (make-expansion-analyzer (λ (stx) (syntax-property-bundle)) #:name 'analyzer2)) |
| 311 | + |
293 | 312 | (define-refactoring-rule rule1 |
294 | 313 | #:description "rule 1" |
| 314 | + #:analyzers (list analyzer1) |
295 | 315 | pattern1 |
296 | 316 | replacement1) |
297 | 317 |
|
298 | 318 | (define-refactoring-rule rule2 |
299 | 319 | #:description "rule 2" |
| 320 | + #:analyzers (list analyzer2) |
300 | 321 | pattern2 |
301 | 322 | replacement2) |
302 | 323 |
|
|
305 | 326 | (check-true (refactoring-suite? suite)) |
306 | 327 | (check-equal? (length (refactoring-suite-rules suite)) 2) |
307 | 328 | (check-true (set? (refactoring-suite-analyzers suite))) |
308 | | - ;; All rules have the same analyzers, so the combined set should have 3 unique analyzers |
309 | | - (check-equal? (set-count (refactoring-suite-analyzers suite)) 3) |
310 | | - (check-true (for/and ([analyzer (in-set (refactoring-suite-analyzers suite))]) |
311 | | - (expansion-analyzer? analyzer)))) |
| 329 | + ;; Should have 2 unique analyzers from the two rules. Sets automatically deduplicate |
| 330 | + ;; analyzers, so if both rules used the same analyzer, the count would be 1. |
| 331 | + (check-equal? (set-count (refactoring-suite-analyzers suite)) 2) |
| 332 | + (check-true (set-member? (refactoring-suite-analyzers suite) analyzer1)) |
| 333 | + (check-true (set-member? (refactoring-suite-analyzers suite) analyzer2))) |
312 | 334 |
|
313 | 335 | (test-case "nested suites combine analyzers correctly" |
| 336 | + (define analyzer1 (make-expansion-analyzer (λ (stx) (syntax-property-bundle)) #:name 'analyzer1)) |
| 337 | + |
314 | 338 | (define-refactoring-rule inner-rule |
315 | 339 | #:description "inner rule" |
| 340 | + #:analyzers (list analyzer1) |
316 | 341 | inner-pattern |
317 | 342 | inner-replacement) |
318 | 343 |
|
319 | 344 | (define inner-suite (refactoring-suite #:rules (list inner-rule))) |
320 | 345 |
|
321 | 346 | (define-refactoring-rule outer-rule |
322 | 347 | #:description "outer rule" |
| 348 | + #:analyzers (list analyzer1) |
323 | 349 | outer-pattern |
324 | 350 | outer-replacement) |
325 | 351 |
|
326 | 352 | (define outer-suite (refactoring-suite #:rules (list outer-rule inner-rule))) |
327 | 353 |
|
328 | | - (check-equal? (set-count (refactoring-suite-analyzers inner-suite)) 3) |
329 | | - ;; Both rules have the same analyzers, so deduplicated should still be 3 |
330 | | - (check-equal? (set-count (refactoring-suite-analyzers outer-suite)) 3)) |
| 354 | + (check-equal? (set-count (refactoring-suite-analyzers inner-suite)) 1) |
| 355 | + ;; Both rules have the same analyzer, so deduplicated should still be 1 |
| 356 | + (check-equal? (set-count (refactoring-suite-analyzers outer-suite)) 1)) |
331 | 357 |
|
332 | 358 | (test-case "define-refactoring-suite with nested suites preserves analyzers" |
| 359 | + (define analyzer-a (make-expansion-analyzer (λ (stx) (syntax-property-bundle)) #:name 'analyzer-a)) |
| 360 | + (define analyzer-b (make-expansion-analyzer (λ (stx) (syntax-property-bundle)) #:name 'analyzer-b)) |
| 361 | + |
333 | 362 | (define-refactoring-rule rule-a |
334 | 363 | #:description "Rule A" |
| 364 | + #:analyzers (list analyzer-a) |
335 | 365 | pattern-a |
336 | 366 | replacement-a) |
337 | 367 |
|
|
340 | 370 |
|
341 | 371 | (define-refactoring-rule rule-b |
342 | 372 | #:description "Rule B" |
| 373 | + #:analyzers (list analyzer-b) |
343 | 374 | pattern-b |
344 | 375 | replacement-b) |
345 | 376 |
|
|
349 | 380 |
|
350 | 381 | ;; Suite B should have both rules |
351 | 382 | (check-equal? (length (refactoring-suite-rules suite-b)) 2) |
352 | | - ;; And should have 3 analyzers (deduplicated from both rules) |
353 | | - (check-equal? (set-count (refactoring-suite-analyzers suite-b)) 3) |
| 383 | + ;; And should have 2 unique analyzers (one from each rule) |
| 384 | + (check-equal? (set-count (refactoring-suite-analyzers suite-b)) 2) |
354 | 385 | (check-true (for/and ([analyzer (in-set (refactoring-suite-analyzers suite-b))]) |
355 | 386 | (expansion-analyzer? analyzer))))) |
0 commit comments