File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88 racket/port
99 "editor.rkt "
1010 "doc-trace.rkt "
11+ "doc-lang.rkt "
1112 "../common/path-util.rkt "
1213 "internal-types.rkt " )
1314
5556(define (check-syntax uri doc-text)
5657 (define path (uri->path uri))
5758 (define text (send doc-text get-text))
58- ; rktd <-> rkt is just like JSON <-> js
59- (define data-file? (equal? (path-get-extension path) #".rktd " ))
59+ (define expand? (requires-expansion? path))
6060 (define new-trace (new build-trace% [src path] [doc-text doc-text]))
6161
6262 (define in (open-input-string text))
63- (define er (expand-source path in new-trace #:expand? (not data-file?) ))
63+ (define er (expand-source path in new-trace #:expand? expand? ))
6464
6565 (send new-trace walk-stx er)
6666 (send new-trace walk-log (ExpandResult-logs er))
6767 (CSResult new-trace text
68- (if data-file ?
69- (and ( ExpandResult-pre-syntax er) #t )
70- (ExpandResult-all-succeed? er))))
68+ (if expand ?
69+ (ExpandResult-all-succeed? er)
70+ (and ( ExpandResult-pre-syntax er) #t ))))
7171
7272(provide
7373 (struct-out CSResult)
Original file line number Diff line number Diff line change 263263 (and (regexp-match? (Known-Language-name-rx language) text)
264264 language)))
265265
266+ (define/contract (racket-data-file-path? path)
267+ (-> path-string? boolean?)
268+ (equal? (path-get-extension path) #".rktd " ))
269+
270+ (define/contract (requires-expansion? path)
271+ (-> path-string? boolean?)
272+ (not (racket-data-file-path? path)))
273+
274+ (define/contract (requires-language-declaration? path)
275+ (-> path-string? boolean?)
276+ (not (racket-data-file-path? path)))
277+
266278(define (uri->suffix uri)
267279 (define extension (path-get-extension (uri->path uri)))
268280 (bytes->string/utf-8 (subbytes extension 1 )))
366378 Known-Language~kw
367379 known-languages
368380 find-language-by-text
381+ racket-data-file-path?
382+ requires-expansion?
383+ requires-language-declaration?
369384 parse-language-prefix
370385 parse-language
371386 guess-language-by-uri
Original file line number Diff line number Diff line change 44 racket/class
55 racket/string
66 racket/set
7- racket/path
87 racket/match
98 racket/list
109 setup/path-to-relative
4443 (define pre-exn (ExpandResult-pre-exn expand-result))
4544 (define post-exn (ExpandResult-post-exn expand-result))
4645 (define maybe-language-diag
47- (and (not (equal? (path-get-extension src) #" .rktd " ) )
46+ (and (requires-language-declaration? src)
4847 (language-diagnostic doc-text)))
4948 (when maybe-language-diag
5049 (add-diag! maybe-language-diag))
Original file line number Diff line number Diff line change 232232 'scribble )
233233 (check-false (guess-language-by-uri "file:///tmp/demo.rkt " )))
234234
235+ (test-case
236+ "rktd files are Racket data, not expandable modules "
237+ (define path (string->path "/tmp/demo.rktd " ))
238+ (check-true (racket-data-file-path? path))
239+ (check-false (requires-expansion? path))
240+ (check-false (requires-language-declaration? path)))
241+
242+ (test-case
243+ "rkt files still require module policy "
244+ (define path (string->path "/tmp/demo.rkt " ))
245+ (check-false (racket-data-file-path? path))
246+ (check-true (requires-expansion? path))
247+ (check-true (requires-language-declaration? path)))
248+
235249 (test-case
236250 "sexp-language? is true only for known sexp families "
237251 (check-true (sexp-language? "#lang racket/base\n(define x 1)\n " ))
You can’t perform that action at this time.
0 commit comments