|
13 | 13 |
|
14 | 14 | (require (for-syntax racket/base
|
15 | 15 | racket/match
|
16 |
| - racket/sequence |
17 |
| - resyntax/test/private/statement |
18 |
| - syntax/parse) |
19 |
| - racket/stxparam |
| 16 | + resyntax/test/private/statement) |
20 | 17 | rackunit
|
21 | 18 | rebellion/base/comparator
|
22 | 19 | rebellion/base/range
|
|
257 | 254 | (require racket/list
|
258 | 255 | racket/syntax-srcloc
|
259 | 256 | resyntax/private/syntax-traversal
|
| 257 | + resyntax/private/universal-tagged-syntax |
260 | 258 | resyntax/test/private/grammar
|
261 | 259 | resyntax/test/private/tokenizer
|
262 | 260 | syntax/parse)
|
|
269 | 267 | (define (read-syntax source-name in)
|
270 | 268 | (define parse-tree (parse source-name (make-refactoring-test-tokenizer in)))
|
271 | 269 | (define cleaned-parse-tree
|
272 |
| - (replace-option-identifiers-with-keywords |
273 |
| - (join-multiline-code-blocks |
274 |
| - (replace-grammar-tags-with-shape-tags parse-tree)))) |
| 270 | + (add-uts-properties |
| 271 | + (replace-option-identifiers-with-keywords |
| 272 | + (join-multiline-code-blocks |
| 273 | + (replace-grammar-tags-with-shape-tags parse-tree))))) |
275 | 274 | (define statements
|
276 | 275 | (syntax-parse cleaned-parse-tree
|
277 | 276 | [(#:program statement ...) (attribute statement)]))
|
278 |
| - (define module-datum |
279 |
| - `(module refactoring-test resyntax/test |
280 |
| - ,@statements)) |
| 277 | + (define raw-module-id (datum->syntax #false 'module #false parse-tree)) |
| 278 | + (define module-level-separators |
| 279 | + (append (list "" "#lang ") (make-list (length statements) "\n") (list ""))) |
| 280 | + (define module-id (syntax-property raw-module-id 'uts-separators module-level-separators)) |
| 281 | + (define raw-modname |
| 282 | + (datum->syntax #false (derive-module-name-from-source source-name) #false parse-tree)) |
| 283 | + (define modname (syntax-property raw-modname 'uts-content "")) |
| 284 | + (define raw-prelude (datum->syntax #false 'resyntax/test #false parse-tree)) |
| 285 | + (define prelude (syntax-property raw-prelude 'uts-content "resyntax/test")) |
| 286 | + (define module-datum (list* module-id modname prelude statements)) |
281 | 287 | (define whole-program-srcloc (syntax-srcloc cleaned-parse-tree))
|
282 |
| - (datum->syntax #f module-datum whole-program-srcloc)) |
| 288 | + (check-universal-tagged-syntax (datum->syntax #false module-datum whole-program-srcloc))) |
| 289 | + |
| 290 | + |
| 291 | + (define (derive-module-name-from-source source-name) |
| 292 | + ; TODO: actually pick a symbol based on the source name instead of ignoring it. |
| 293 | + 'refactoring-test) |
283 | 294 |
|
284 | 295 |
|
285 | 296 | (define (replace-grammar-tags-with-shape-tags grammar-stx)
|
|
329 | 340 | #:parent-props-modifier (λ (stx) stx)))
|
330 | 341 |
|
331 | 342 |
|
| 343 | + (define (add-uts-properties stx) |
| 344 | + (syntax-traverse stx |
| 345 | + #:datum-literals (require header test no-change-test analysis-test) |
| 346 | + |
| 347 | + [:id |
| 348 | + (define as-string (symbol->string (syntax-e this-syntax))) |
| 349 | + (syntax-property this-syntax 'uts-content as-string)] |
| 350 | + |
| 351 | + [((~and tag #:statement) require-id:require mod suite) |
| 352 | + (define tag-with-prop |
| 353 | + (syntax-property (attribute tag) 'uts-separators (list "" ": " " " "\n"))) |
| 354 | + (define new-datum |
| 355 | + (list tag-with-prop |
| 356 | + (add-uts-properties (attribute require-id)) |
| 357 | + (add-uts-properties (attribute mod)) |
| 358 | + (add-uts-properties (attribute suite)))) |
| 359 | + (datum->syntax #false new-datum this-syntax this-syntax)] |
| 360 | + |
| 361 | + [((~and tag #:statement) header-id:header code) |
| 362 | + (define tag-with-prop |
| 363 | + (syntax-property (attribute tag) 'uts-separators (list "" ":\n" ""))) |
| 364 | + (define new-datum |
| 365 | + (list tag-with-prop |
| 366 | + (add-uts-properties (attribute header-id)) |
| 367 | + (add-uts-properties (attribute code)))) |
| 368 | + (datum->syntax #false new-datum this-syntax this-syntax)] |
| 369 | + |
| 370 | + [((~and tag #:statement) (~and test-id (~or test no-change-test analysis-test)) arg ...) |
| 371 | + (define separators (append (list "" ": " "\n") (make-list (length (attribute arg)) ""))) |
| 372 | + (define tag-with-prop (syntax-property (attribute tag) 'uts-separators separators)) |
| 373 | + (define new-datum |
| 374 | + (list* tag-with-prop |
| 375 | + (add-uts-properties (attribute test-id)) |
| 376 | + (for/list ([arg-stx (in-list (attribute arg))]) |
| 377 | + (add-uts-properties arg-stx)))) |
| 378 | + (datum->syntax #false new-datum this-syntax this-syntax)] |
| 379 | + |
| 380 | + [((~and tag #:code-line) code:str) |
| 381 | + (define tag-with-prop (syntax-property (attribute tag) 'uts-separators (list "- " ""))) |
| 382 | + (define code-with-prop |
| 383 | + (syntax-property (attribute code) 'uts-content (syntax-e (attribute code)))) |
| 384 | + (datum->syntax #false (list tag-with-prop code-with-prop) this-syntax this-syntax)] |
| 385 | + |
| 386 | + [((~and tag #:code-block) code:str) |
| 387 | + (define dash-line "--------------------\n") |
| 388 | + (define tag-with-prop |
| 389 | + (syntax-property (attribute tag) 'uts-separators (list dash-line dash-line))) |
| 390 | + (define code-with-prop |
| 391 | + (syntax-property (attribute code) 'uts-content (syntax-e (attribute code)))) |
| 392 | + (datum->syntax #false (list tag-with-prop code-with-prop) this-syntax this-syntax)] |
| 393 | + |
| 394 | + [((~and tag #:option) option:keyword expr) |
| 395 | + (define expr-ends-in-newline? |
| 396 | + (syntax-parse (attribute expr) |
| 397 | + [((~or #:code-line #:code-block) _ ...) #true] |
| 398 | + [_ #false])) |
| 399 | + (define separators (list "@" "" (if expr-ends-in-newline? "" "\n"))) |
| 400 | + (define tag-with-prop (syntax-property (attribute tag) 'uts-separators separators)) |
| 401 | + (define option-stx (attribute option)) |
| 402 | + (define option-as-string (keyword->string (syntax-e option-stx))) |
| 403 | + (define option-with-prop (syntax-property option-stx 'uts-content option-as-string)) |
| 404 | + (define new-datum (list tag-with-prop option-with-prop (add-uts-properties (attribute expr)))) |
| 405 | + (datum->syntax #false new-datum this-syntax this-syntax)] |
| 406 | + |
| 407 | + [((~and tag #:range-set) line-range ...) |
| 408 | + (define separators |
| 409 | + (append (list "") |
| 410 | + (make-list (sub1 (length (attribute line-range))) ", ") |
| 411 | + (list ""))) |
| 412 | + (define tag-with-prop (syntax-property (attribute tag) 'uts-separators separators)) |
| 413 | + (define new-datum |
| 414 | + (cons tag-with-prop |
| 415 | + (for/list ([line-range-stx (in-list (attribute line-range))]) |
| 416 | + (add-uts-properties line-range-stx)))) |
| 417 | + (datum->syntax #false new-datum this-syntax this-syntax)] |
| 418 | + |
| 419 | + [((~and tag #:line-range) first last) |
| 420 | + (define tag-with-prop (syntax-property (attribute tag) 'uts-separators (list "" ".." ""))) |
| 421 | + (define new-datum |
| 422 | + (list tag-with-prop |
| 423 | + (add-uts-properties (attribute first)) |
| 424 | + (add-uts-properties (attribute last)))) |
| 425 | + (datum->syntax #false new-datum this-syntax this-syntax)] |
| 426 | + |
| 427 | + [(~or :str :number) |
| 428 | + (define as-string (format "~v" (syntax-e this-syntax))) |
| 429 | + (syntax-property this-syntax 'uts-content as-string)] |
| 430 | + |
| 431 | + #:parent-context-modifier (λ (stx) stx) |
| 432 | + #:parent-srcloc-modifier (λ (stx) stx) |
| 433 | + #:parent-props-modifier (λ (stx) stx))) |
| 434 | + |
| 435 | + |
332 | 436 | (define (read-using-syntax-reader syntax-reader in)
|
333 | 437 | (syntax->datum (syntax-reader #false in)))
|
334 | 438 |
|
|
372 | 476 | #:do [(define code-strings (map syntax-e (attribute code)))]
|
373 | 477 | #:when (for/and ([s (in-list code-strings)])
|
374 | 478 | (string-with-one-newline-at-end? s))
|
375 |
| - #:with statement-tag-with-seps |
376 |
| - (syntax-property (attribute statement-tag) |
377 |
| - 'uts-separators |
378 |
| - (list* "" ": " "\n" (make-list (length (attribute code)) ""))) |
379 | 479 | #:with code-line-with-seps (syntax-property #'#:code-line 'uts-separators (list "- " ""))
|
380 |
| - #:with (replacement-code ...) |
381 |
| - (for/list ([code-stx (in-list (attribute code))]) |
382 |
| - (syntax-property code-stx 'uts-atom-content (syntax-e code-stx))) |
383 |
| - (statement-tag-with-seps test-id test-name (code-line-with-seps replacement-code) ...)) |
| 480 | + (statement-tag test-id test-name (code-line-with-seps code) ...)) |
384 | 481 |
|
385 | 482 |
|
386 | 483 | (define (string-with-one-newline-at-end? s)
|
|
0 commit comments