diff --git a/pkgs/racket-test-core/tests/racket/read.rktl b/pkgs/racket-test-core/tests/racket/read.rktl index 3bd5d0953a..dda0da359c 100644 --- a/pkgs/racket-test-core/tests/racket/read.rktl +++ b/pkgs/racket-test-core/tests/racket/read.rktl @@ -1339,6 +1339,24 @@ (err/rt-test (read-language p) (lambda (exn) (regexp-match? #rx"read-language" (exn-message exn))))) +(parameterize ([read-accept-reader #t]) + (err/rt-test (read (open-input-string "#lang")) + (lambda (exn) (regexp-match? #rx"expected a single space" (exn-message exn)))) + (err/rt-test (read (open-input-string "#lang ")) + (lambda (exn) (regexp-match? #rx"expected a non-empty sequence of" (exn-message exn)))) + (err/rt-test (read (open-input-string "#lang ")) + (lambda (exn) (regexp-match? #rx"expected a single space" (exn-message exn)))) + (err/rt-test (read (open-input-string "#lang x")) + (lambda (exn) (regexp-match? #rx"expected a single space" (exn-message exn)))) + (err/rt-test (read (open-input-string "#lang .")) + (lambda (exn) (regexp-match? #rx"expected only" (exn-message exn)))) + (err/rt-test (read (open-input-string "#lang x.")) + (lambda (exn) (regexp-match? #rx"expected only" (exn-message exn)))) + (err/rt-test (read (open-input-string "#lang \n")) + (lambda (exn) (regexp-match? #rx"expected only" (exn-message exn)))) + (err/rt-test (read (open-input-string "#lang \nx")) + (lambda (exn) (regexp-match? #rx"expected only" (exn-message exn))))) + ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (require racket/flonum diff --git a/racket/src/expander/read/extension.rkt b/racket/src/expander/read/extension.rkt index f0ed6586d3..bbb7bd43e7 100644 --- a/racket/src/expander/read/extension.rkt +++ b/racket/src/expander/read/extension.rkt @@ -49,6 +49,7 @@ extend-str)) (read-lang extend-str read-recur in config + #:one-space? #t #:who '|#lang| #:get-info? get-info?)) @@ -68,6 +69,7 @@ (define (read-lang extend-str read-recur in config #:init-c [init-c #f] + #:one-space? [one-space? #f] #:get-info? [get-info? #f] #:who who) (unless (and (check-parameter read-accept-reader config) @@ -90,7 +92,14 @@ (reader-error in config #:due-to c "found non-character while reading `#~a`" extend-str)] - [(char-whitespace? c) (void)] + [(and (char-whitespace? c) + (positive? (accum-string-count accum-str))) + (void)] + [(and one-space? + (char=? c #\space)) + (reader-error in config + "expected a single space after `~a`" + extend-str)] [(or (char-lang-nonsep? c) (char=? #\/ c)) (consume-char in c) @@ -107,8 +116,9 @@ (define lang-str (accum-string-get! accum-str config)) (when (equal? lang-str "") (reader-error in config - "expected a non-empty sequence of alphanumeric, `-`, `+`, `_`, or `/` after `~a`" - extend-str)) + "expected a non-empty sequence of alphanumeric, `-`, `+`, `_`, or `/` after `~a~a`" + extend-str + (if one-space? " " ""))) (when (char=? #\/ (string-ref lang-str 0)) (reader-error in config diff --git a/racket/src/racket/src/startup.inc b/racket/src/racket/src/startup.inc index 8feb33c329..05abf28116 100644 --- a/racket/src/racket/src/startup.inc +++ b/racket/src/racket/src/startup.inc @@ -59649,53 +59649,53 @@ static const char *startup_source = "(if(check-parameter 1/read-accept-reader config_0)" "(void)" "(let-values()" -"(let-values(((in52_0) in_0)" -"((config53_0) config_0)" -" ((temp54_0) \"`~a` not enabled\")" -"((extend-str55_0) extend-str_0))" +"(let-values(((in54_0) in_0)" +"((config55_0) config_0)" +" ((temp56_0) \"`~a` not enabled\")" +"((extend-str57_0) extend-str_0))" "(reader-error12.1" " unsafe-undefined" " '#\\x" " #f" " unsafe-undefined" -" in52_0" -" config53_0" -" temp54_0" -"(list extend-str55_0)))))" +" in54_0" +" config55_0" +" temp56_0" +"(list extend-str57_0)))))" "(values))))" "(let-values(((mod-path-wrapped_0)(read-one_0 #f in_0(next-readtable config_0))))" "(begin" "(if(eof-object? mod-path-wrapped_0)" "(let-values()" -"(let-values(((in56_0) in_0)" -"((config57_0) config_0)" -"((mod-path-wrapped58_0) mod-path-wrapped_0)" -" ((temp59_0) \"expected a datum after `~a`, found end-of-file\")" -"((extend-str60_0) extend-str_0))" +"(let-values(((in58_0) in_0)" +"((config59_0) config_0)" +"((mod-path-wrapped60_0) mod-path-wrapped_0)" +" ((temp61_0) \"expected a datum after `~a`, found end-of-file\")" +"((extend-str62_0) extend-str_0))" "(reader-error12.1" " unsafe-undefined" -" mod-path-wrapped58_0" +" mod-path-wrapped60_0" " #f" " unsafe-undefined" -" in56_0" -" config57_0" -" temp59_0" -"(list extend-str60_0))))" +" in58_0" +" config59_0" +" temp61_0" +"(list extend-str62_0))))" "(void))" -"(let-values(((temp47_0)((read-config-coerce config_0) #f mod-path-wrapped_0 #f))" -"((read-recur48_0) read-recur_0)" -"((in49_0) in_0)" -"((config50_0) config_0)" -"((mod-path-wrapped51_0) mod-path-wrapped_0))" -"(read-extension44.1" +"(let-values(((temp49_0)((read-config-coerce config_0) #f mod-path-wrapped_0 #f))" +"((read-recur50_0) read-recur_0)" +"((in51_0) in_0)" +"((config52_0) config_0)" +"((mod-path-wrapped53_0) mod-path-wrapped_0))" +"(read-extension46.1" " #f" -" mod-path-wrapped51_0" +" mod-path-wrapped53_0" " #f" " '|#reader|" -" temp47_0" -" read-recur48_0" -" in49_0" -" config50_0)))))))))" +" temp49_0" +" read-recur50_0" +" in51_0" +" config52_0)))))))))" "(define-values" "(read-extension-lang7.1)" "(lambda(get-info?1_0 read-recur3_0 dispatch-c4_0 in5_0 config6_0)" @@ -59716,33 +59716,35 @@ static const char *startup_source = "(if(char=? c_0 '#\\space)" "(void)" "(let-values()" -"(let-values(((in67_0) in_0)" -"((config68_0) config_0)" -" ((temp69_0) \"expected a single space after `~a`\")" -"((extend-str70_0) extend-str_0))" +"(let-values(((in70_0) in_0)" +"((config71_0) config_0)" +" ((temp72_0) \"expected a single space after `~a`\")" +"((extend-str73_0) extend-str_0))" "(reader-error12.1" " unsafe-undefined" " '#\\x" " #f" " unsafe-undefined" -" in67_0" -" config68_0" -" temp69_0" -"(list extend-str70_0)))))" -"(let-values(((extend-str61_0) extend-str_0)" -"((read-recur62_0) read-recur_0)" -"((in63_0) in_0)" -"((config64_0) config_0)" -"((temp65_0) '|#lang|)" -"((get-info?66_0) get-info?_0))" -"(read-lang29.1" -" get-info?66_0" +" in70_0" +" config71_0" +" temp72_0" +"(list extend-str73_0)))))" +"(let-values(((extend-str63_0) extend-str_0)" +"((read-recur64_0) read-recur_0)" +"((in65_0) in_0)" +"((config66_0) config_0)" +"((temp67_0) #t)" +"((temp68_0) '|#lang|)" +"((get-info?69_0) get-info?_0))" +"(read-lang31.1" +" get-info?69_0" " #f" -" temp65_0" -" extend-str61_0" -" read-recur62_0" -" in63_0" -" config64_0))))))))))))))" +" temp67_0" +" temp68_0" +" extend-str63_0" +" read-recur64_0" +" in65_0" +" config66_0))))))))))))))" "(define-values" "(read-extension-#!16.1)" "(lambda(get-info?10_0 read-recur12_0 dispatch-c13_0 in14_0 config15_0)" @@ -59761,38 +59763,40 @@ static const char *startup_source = "(if(char-lang-nonsep? c_0)" "(void)" "(let-values()" -"(let-values(((in78_0) in_0)" -"((config79_0) config_0)" -"((temp80_0)" +"(let-values(((in81_0) in_0)" +"((config82_0) config_0)" +"((temp83_0)" "(if(char? c_0)(string dispatch-c_0 '#\\! c_0)(string dispatch-c_0 '#\\!))))" -"(bad-syntax-error20.1 '#\\x in78_0 config79_0 temp80_0))))" -"(let-values(((temp71_0)(string dispatch-c_0 '#\\!))" -"((read-recur72_0) read-recur_0)" -"((in73_0) in_0)" -"((config74_0) config_0)" -"((c75_0) c_0)" -"((temp76_0) '|#!|)" -"((get-info?77_0) get-info?_0))" -"(read-lang29.1" -" get-info?77_0" -" c75_0" -" temp76_0" -" temp71_0" -" read-recur72_0" -" in73_0" -" config74_0)))))))))))))" +"(bad-syntax-error20.1 '#\\x in81_0 config82_0 temp83_0))))" +"(let-values(((temp74_0)(string dispatch-c_0 '#\\!))" +"((read-recur75_0) read-recur_0)" +"((in76_0) in_0)" +"((config77_0) config_0)" +"((c78_0) c_0)" +"((temp79_0) '|#!|)" +"((get-info?80_0) get-info?_0))" +"(read-lang31.1" +" get-info?80_0" +" c78_0" +" #f" +" temp79_0" +" temp74_0" +" read-recur75_0" +" in76_0" +" config77_0)))))))))))))" "(define-values" -"(read-lang29.1)" -"(lambda(get-info?20_0 init-c19_0 who21_0 extend-str25_0 read-recur26_0 in27_0 config28_0)" +"(read-lang31.1)" +"(lambda(get-info?21_0 init-c19_0 one-space?20_0 who22_0 extend-str27_0 read-recur28_0 in29_0 config30_0)" "(begin" -" 'read-lang29" -"(let-values(((extend-str_0) extend-str25_0))" -"(let-values(((read-recur_0) read-recur26_0))" -"(let-values(((in_0) in27_0))" -"(let-values(((config_0) config28_0))" +" 'read-lang31" +"(let-values(((extend-str_0) extend-str27_0))" +"(let-values(((read-recur_0) read-recur28_0))" +"(let-values(((in_0) in29_0))" +"(let-values(((config_0) config30_0))" "(let-values(((init-c_0) init-c19_0))" -"(let-values(((get-info?_0) get-info?20_0))" -"(let-values(((who_0) who21_0))" +"(let-values(((one-space?_0) one-space?20_0))" +"(let-values(((get-info?_0) get-info?21_0))" +"(let-values(((who_0) who22_0))" "(let-values()" "(let-values((()" "(begin" @@ -59801,19 +59805,19 @@ static const char *startup_source = " #f)" "(void)" "(let-values()" -"(let-values(((in88_0) in_0)" -"((config89_0) config_0)" -" ((temp90_0) \"`~a` not enabled\")" -"((extend-str91_0) extend-str_0))" +"(let-values(((in91_0) in_0)" +"((config92_0) config_0)" +" ((temp93_0) \"`~a` not enabled\")" +"((extend-str94_0) extend-str_0))" "(reader-error12.1" " unsafe-undefined" " '#\\x" " #f" " unsafe-undefined" -" in88_0" -" config89_0" -" temp90_0" -"(list extend-str91_0)))))" +" in91_0" +" config92_0" +" temp93_0" +"(list extend-str94_0)))))" "(values))))" "(let-values(((line_0 col_0 pos_0)(port-next-location in_0)))" "(let-values(((accum-str_0)(accum-string-init! config_0)))" @@ -59850,71 +59854,72 @@ static const char *startup_source = "(let-values()" "(begin" "(consume-char/special in_0 config_0 c_0)" -"(let-values(((in92_0) in_0)" -"((config93_0) config_0)" -"((c94_0) c_0)" -"((temp95_0)" -" \"found non-character while reading `#~a`\")" -"((extend-str96_0)" +"(let-values(((in95_0) in_0)" +"((config96_0) config_0)" +"((c97_0) c_0)" +"((temp98_0)" +" \"found non-character while reading `#~a`\")" +"((extend-str99_0)" " extend-str_0))" "(reader-error12.1" " unsafe-undefined" -" c94_0" +" c97_0" " #f" " unsafe-undefined" -" in92_0" -" config93_0" -" temp95_0" -"(list extend-str96_0)))))" -"(if(char-whitespace? c_0)" +" in95_0" +" config96_0" +" temp98_0" +"(list extend-str99_0)))))" +"(if(if(char-whitespace? c_0)" +"(positive?" +"(accum-string-count accum-str_0))" +" #f)" "(let-values()(void))" +"(if(if one-space?_0" +"(char=? c_0 '#\\space)" +" #f)" +"(let-values()" +"(let-values(((in100_0) in_0)" +"((config101_0) config_0)" +"((temp102_0)" +" \"expected a single space after `~a`\")" +"((extend-str103_0)" +" extend-str_0))" +"(reader-error12.1" +" unsafe-undefined" +" '#\\x" +" #f" +" unsafe-undefined" +" in100_0" +" config101_0" +" temp102_0" +"(list extend-str103_0))))" "(if(let-values(((or-part_0)" -"(char-lang-nonsep? c_0)))" +"(char-lang-nonsep?" +" c_0)))" "(if or-part_0" " or-part_0" "(char=? '#\\/ c_0)))" "(let-values()" "(begin" "(consume-char in_0 c_0)" -"(accum-string-add! accum-str_0 c_0)" +"(accum-string-add!" +" accum-str_0" +" c_0)" "(loop_0)))" "(let-values()" "(begin" "(consume-char in_0 c_0)" -"(let-values(((in97_0) in_0)" -"((config98_0) config_0)" -"((temp99_0)" -"(string-append" -" \"expected only alphanumeric, `-`, `+`, `_`, or `/`\"" -" \" characters for `~a`, found `~a`\"))" -"((extend-str100_0)" -" extend-str_0)" -"((c101_0) c_0))" -"(reader-error12.1" -" unsafe-undefined" -" '#\\x" -" #f" -" unsafe-undefined" -" in97_0" -" config98_0" -" temp99_0" -"(list" -" extend-str100_0" -" c101_0))))))))))))))" -" loop_0))" -"(values))))" -"(let-values(((lang-str_0)" -"(let-values(((accum-str102_0) accum-str_0)((config103_0) config_0))" -"(accum-string-get!6.1 0 accum-str102_0 config103_0))))" -"(let-values((()" -"(begin" -" (if (equal? lang-str_0 \"\")" -"(let-values()" "(let-values(((in104_0) in_0)" -"((config105_0) config_0)" +"((config105_0)" +" config_0)" "((temp106_0)" -" \"expected a non-empty sequence of alphanumeric, `-`, `+`, `_`, or `/` after `~a`\")" -"((extend-str107_0) extend-str_0))" +"(string-append" +" \"expected only alphanumeric, `-`, `+`, `_`, or `/`\"" +" \" characters for `~a`, found `~a`\"))" +"((extend-str107_0)" +" extend-str_0)" +"((c108_0) c_0))" "(reader-error12.1" " unsafe-undefined" " '#\\x" @@ -59923,27 +59928,53 @@ static const char *startup_source = " in104_0" " config105_0" " temp106_0" -"(list extend-str107_0))))" +"(list" +" extend-str107_0" +" c108_0)))))))))))))))" +" loop_0))" +"(values))))" +"(let-values(((lang-str_0)" +"(let-values(((accum-str109_0) accum-str_0)((config110_0) config_0))" +"(accum-string-get!6.1 0 accum-str109_0 config110_0))))" +"(let-values((()" +"(begin" +" (if (equal? lang-str_0 \"\")" +"(let-values()" +"(let-values(((in111_0) in_0)" +"((config112_0) config_0)" +"((temp113_0)" +" \"expected a non-empty sequence of alphanumeric, `-`, `+`, `_`, or `/` after `~a~a`\")" +"((extend-str114_0) extend-str_0)" +" ((temp115_0) (if one-space?_0 \" \" \"\")))" +"(reader-error12.1" +" unsafe-undefined" +" '#\\x" +" #f" +" unsafe-undefined" +" in111_0" +" config112_0" +" temp113_0" +"(list extend-str114_0 temp115_0))))" "(void))" "(values))))" "(let-values((()" "(begin" "(if(char=? '#\\/(string-ref lang-str_0 0))" "(let-values()" -"(let-values(((in108_0) in_0)" -"((config109_0) config_0)" -"((temp110_0)" -" \"expected a name that does not start `/` after `~a`\")" -"((extend-str111_0) extend-str_0))" +"(let-values(((in116_0) in_0)" +"((config117_0) config_0)" +"((temp118_0)" +" \"expected a name that does not start `/` after `~a`\")" +"((extend-str119_0) extend-str_0))" "(reader-error12.1" " unsafe-undefined" " '#\\x" " #f" " unsafe-undefined" -" in108_0" -" config109_0" -" temp110_0" -"(list extend-str111_0))))" +" in116_0" +" config117_0" +" temp118_0" +"(list extend-str119_0))))" "(void))" "(values))))" "(let-values((()" @@ -59952,42 +59983,42 @@ static const char *startup_source = " '#\\/" "(string-ref lang-str_0(sub1(string-length lang-str_0))))" "(let-values()" -"(let-values(((in112_0) in_0)" -"((config113_0) config_0)" -"((temp114_0)" -" \"expected a name that does not end `/` after `~a`\")" -"((extend-str115_0) extend-str_0))" +"(let-values(((in120_0) in_0)" +"((config121_0) config_0)" +"((temp122_0)" +" \"expected a name that does not end `/` after `~a`\")" +"((extend-str123_0) extend-str_0))" "(reader-error12.1" " unsafe-undefined" " '#\\x" " #f" " unsafe-undefined" -" in112_0" -" config113_0" -" temp114_0" -"(list extend-str115_0))))" +" in120_0" +" config121_0" +" temp122_0" +"(list extend-str123_0))))" "(void))" "(values))))" "(let-values(((submod-path_0)" "(list* 'submod(string->symbol lang-str_0) '(reader))))" "(let-values(((reader-path_0)" -" (string->symbol (string-append lang-str_0 \"/lang/reader\"))))" -"(let-values(((submod-path81_0) submod-path_0)" -"((reader-path82_0) reader-path_0)" -"((read-recur83_0) read-recur_0)" -"((in84_0) in_0)" -"((temp85_0)(reading-at config_0 line_0 col_0 pos_0))" -"((get-info?86_0) get-info?_0)" -"((who87_0) who_0))" -"(read-extension44.1" -" get-info?86_0" +" (string->symbol (string-append lang-str_0 \"/lang/reader\"))))" +"(let-values(((submod-path84_0) submod-path_0)" +"((reader-path85_0) reader-path_0)" +"((read-recur86_0) read-recur_0)" +"((in87_0) in_0)" +"((temp88_0)(reading-at config_0 line_0 col_0 pos_0))" +"((get-info?89_0) get-info?_0)" +"((who90_0) who_0))" +"(read-extension46.1" +" get-info?89_0" " unsafe-undefined" -" submod-path81_0" -" who87_0" -" reader-path82_0" -" read-recur83_0" -" in84_0" -" temp85_0))))))))))))))))))))))))" +" submod-path84_0" +" who90_0" +" reader-path85_0" +" read-recur86_0" +" in87_0" +" temp88_0)))))))))))))))))))))))))" "(define-values" "(char-lang-nonsep?)" "(lambda(c_0)" @@ -60048,46 +60079,46 @@ static const char *startup_source = "(if(eqv? c_0(car wanted_1))" "(void)" "(let-values()" -"(let-values(((in118_0) in_0)" -"((config119_0) config_0)" -"((temp120_0)" -"(let-values(((accum-str122_0) accum-str_0)" -"((config123_0) config_0))" -"(accum-string-get!6.1 0 accum-str122_0 config123_0)))" -"((c121_0) c_0))" -"(bad-syntax-error20.1 c121_0 in118_0 config119_0 temp120_0))))" +"(let-values(((in126_0) in_0)" +"((config127_0) config_0)" +"((temp128_0)" +"(let-values(((accum-str130_0) accum-str_0)" +"((config131_0) config_0))" +"(accum-string-get!6.1 0 accum-str130_0 config131_0)))" +"((c129_0) c_0))" +"(bad-syntax-error20.1 c129_0 in126_0 config127_0 temp128_0))))" "(loop_0(cdr wanted_1))))))))))" " loop_0)" " wanted_0)" -"(let-values(((accum-str116_0) accum-str_0)((config117_0) config_0))" -"(accum-string-get!6.1 0 accum-str116_0 config117_0)))))))" +"(let-values(((accum-str124_0) accum-str_0)((config125_0) config_0))" +"(accum-string-get!6.1 0 accum-str124_0 config125_0)))))))" "(define-values" -"(read-extension44.1)" -"(lambda(get-info?34_0" -" mod-path-wrapped33_0" -" try-first-mod-path32_0" -" who35_0" -" mod-path-datum40_0" -" read-recur41_0" -" in42_0" -" config43_0)" +"(read-extension46.1)" +"(lambda(get-info?36_0" +" mod-path-wrapped35_0" +" try-first-mod-path34_0" +" who37_0" +" mod-path-datum42_0" +" read-recur43_0" +" in44_0" +" config45_0)" "(begin" -" 'read-extension44" -"(let-values(((try-first-mod-path_0) try-first-mod-path32_0))" -"(let-values(((mod-path-datum_0) mod-path-datum40_0))" -"(let-values(((read-recur_0) read-recur41_0))" -"(let-values(((in_0) in42_0))" -"(let-values(((config_0) config43_0))" +" 'read-extension46" +"(let-values(((try-first-mod-path_0) try-first-mod-path34_0))" +"(let-values(((mod-path-datum_0) mod-path-datum42_0))" +"(let-values(((read-recur_0) read-recur43_0))" +"(let-values(((in_0) in44_0))" +"(let-values(((config_0) config45_0))" "(let-values(((mod-path-wrapped_0)" -"(if(eq? mod-path-wrapped33_0 unsafe-undefined)" +"(if(eq? mod-path-wrapped35_0 unsafe-undefined)" "((read-config-coerce config_0)" " #t" " mod-path-datum_0" -"(let-values(((in124_0) in_0)((config125_0) config_0))" -"(port+config->srcloc51.1 #f in124_0 config125_0)))" -" mod-path-wrapped33_0)))" -"(let-values(((get-info?_0) get-info?34_0))" -"(let-values(((who_0) who35_0))" +"(let-values(((in132_0) in_0)((config133_0) config_0))" +"(port+config->srcloc51.1 #f in132_0 config133_0)))" +" mod-path-wrapped35_0)))" +"(let-values(((get-info?_0) get-info?36_0))" +"(let-values(((who_0) who37_0))" "(let-values()" "(let-values((()(begin(force-parameters! config_0)(values))))" "(let-values(((guard_0)(1/current-reader-guard)))"