|
6 | 6 |
|
7 | 7 | (provide |
8 | 8 | (contract-out |
9 | | - [source-analyze (->* (source?) (#:lines range-set?) source-code-analysis?)] |
| 9 | + [source-analyze (->* (source? #:analyzers (listof expansion-analyzer?)) |
| 10 | + (#:lines range-set?) |
| 11 | + source-code-analysis?)] |
10 | 12 | [source-code-analysis? (-> any/c boolean?)] |
11 | 13 | [source-code-analysis-code (-> source-code-analysis? source?)] |
12 | 14 | [source-code-analysis-visited-forms (-> source-code-analysis? (listof syntax?))] |
|
56 | 58 | (code visited-forms expansion-time-output namespace added-syntax-properties)) |
57 | 59 |
|
58 | 60 |
|
59 | | -(define (source-analyze code #:lines [lines (range-set (unbounded-range #:comparator natural<=>))]) |
| 61 | +(define (source-analyze code |
| 62 | + #:lines [lines (range-set (unbounded-range #:comparator natural<=>))] |
| 63 | + #:analyzers analyzers) |
60 | 64 | (define ns (make-base-namespace)) |
61 | 65 | (parameterize ([current-directory (or (source-directory code) (current-directory))] |
62 | 66 | [current-namespace ns]) |
|
136 | 140 | #:into (into-sorted-map syntax-path<=>))) |
137 | 141 |
|
138 | 142 | (define expansion-analyzer-props |
139 | | - (transduce (sequence-append |
140 | | - (syntax-property-bundle-entries |
141 | | - (expansion-analyze identifier-usage-analyzer expanded)) |
142 | | - (syntax-property-bundle-entries |
143 | | - (expansion-analyze ignored-result-values-analyzer expanded)) |
144 | | - (syntax-property-bundle-entries |
145 | | - (expansion-analyze variable-mutability-analyzer expanded))) |
| 143 | + (transduce analyzers |
| 144 | + (append-mapping |
| 145 | + (λ (analyzer) |
| 146 | + (syntax-property-bundle-entries |
| 147 | + (expansion-analyze analyzer expanded)))) |
146 | 148 | #:into into-syntax-property-bundle)) |
147 | 149 |
|
148 | 150 | (define expansion-analyzer-props-adjusted-for-visits |
|
234 | 236 | (define (extract-module-require-spec mod-stx) |
235 | 237 | (syntax-parse mod-stx |
236 | 238 | [(_ name _ . _) `',(syntax-e #'name)])) |
| 239 | + |
| 240 | + |
| 241 | +(module+ test |
| 242 | + (require rackunit) |
| 243 | + |
| 244 | + (test-case "source-analyze with custom analyzers list" |
| 245 | + ;; Test that source-analyze accepts an analyzers parameter |
| 246 | + (define test-source (string-source "#lang racket/base (define x 1)")) |
| 247 | + |
| 248 | + ;; Test with empty analyzers list |
| 249 | + (define analysis-empty (source-analyze test-source #:analyzers '())) |
| 250 | + (check-true (source-code-analysis? analysis-empty)) |
| 251 | + |
| 252 | + ;; Test with single analyzer |
| 253 | + (define analysis-single |
| 254 | + (source-analyze test-source #:analyzers (list identifier-usage-analyzer))) |
| 255 | + (check-true (source-code-analysis? analysis-single)) |
| 256 | + |
| 257 | + ;; Test with default analyzers (should match default behavior) |
| 258 | + (define analysis-default |
| 259 | + (source-analyze test-source |
| 260 | + #:analyzers (list identifier-usage-analyzer |
| 261 | + ignored-result-values-analyzer |
| 262 | + variable-mutability-analyzer))) |
| 263 | + (check-true (source-code-analysis? analysis-default)))) |
0 commit comments