Skip to content

Commit

Permalink
add alternative (R7RS) spelling of booleans (cisco#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarhmander authored Apr 26, 2021
1 parent 405a947 commit 728813f
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 145 deletions.
2 changes: 2 additions & 0 deletions LOG
Original file line number Diff line number Diff line change
Expand Up @@ -2171,3 +2171,5 @@
- fixed the documentation of load-shared-object to mention an up-to-date
dll for Windows
foreign.stex
- New spellings #true and #false for #t and #f are recognized
read.ss 6.ms
6 changes: 6 additions & 0 deletions csug/intro.stex
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ parentheses, open and close brackets, double quotes, semi-colon,
and \scheme{#}), {\ChezScheme} also treats as delimiters
open and close braces, single quote, backward quote, and comma.

Finally, {\ChezScheme} accepts \index{\scheme{#true}}\scheme{#true} and
\index{\scheme{#false}}\scheme{#false} as alternative spellings of the booleans
\scheme{#t} and \scheme{#f}. Like the external representation of numbers, case
is not significant; for example, \scheme{#T}, \scheme{#True} and \scheme{#TRUE}
are all equivalent.

The {\ChezScheme} lexical extensions described above are disabled in an
input stream after an \scheme{#!r6rs} comment directive has been seen,
unless a \scheme{#!chezscheme} comment directive has been seen since.
Expand Down
43 changes: 42 additions & 1 deletion mats/6.ms
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,30 @@
(lambda () (close-input-port ip))))])
vals)
'(atomic eat 1 4))
(equal?
(call-with-values (lambda () (with-input-from-string "#t" read-token)) list)
'(atomic #t 0 2))
(equal?
(call-with-values (lambda () (with-input-from-string "#true" read-token)) list)
'(atomic #t 0 5))
(equal?
(call-with-values (lambda () (with-input-from-string "#True" read-token)) list)
'(atomic #t 0 5))
(equal?
(call-with-values (lambda () (with-input-from-string "#TRUE" read-token)) list)
'(atomic #t 0 5))
(equal?
(call-with-values (lambda () (with-input-from-string "#f" read-token)) list)
'(atomic #f 0 2))
(equal?
(call-with-values (lambda () (with-input-from-string "#false" read-token)) list)
'(atomic #f 0 6))
(equal?
(call-with-values (lambda () (with-input-from-string "#False" read-token)) list)
'(atomic #f 0 6))
(equal?
(call-with-values (lambda () (with-input-from-string "#FALSE" read-token)) list)
'(atomic #f 0 6))
)

(define read-test
Expand Down Expand Up @@ -1792,6 +1816,11 @@
"; Test error \"unexpected end-of-file reading character\"\n#\\"
"; Test error \"unexpected end-of-file reading character\"\n#\\new"
"; Test error \"unexpected end-of-file reading character\"\n#\\02"
"; Test error \"unexpected end-of-file reading boolean\"\n\n#tr"
"; Test error \"unexpected end-of-file reading boolean\"\n\n#tru"
"; Test error \"unexpected end-of-file reading boolean\"\n\n#fa"
"; Test error \"unexpected end-of-file reading boolean\"\n\n#fal"
"; Test error \"unexpected end-of-file reading boolean\"\n\n#fals"
"; Test error \"unexpected end-of-file reading expression comment\"\n\n(define oops '#; ; that's all I've got!\n"
"; Test error \"unexpected end-of-file reading gensym\"\n(pretty-print '#{"
"; Test error \"unexpected end-of-file reading gensym\"\n(pretty-print '#{foo"
Expand Down Expand Up @@ -1860,6 +1889,13 @@
"; Test error \"octal character syntax not allowed in #!r6rs mode\"\n\n#!r6rs #\\010\n"
"; Test error \"invalid delimiter 1 for character\"\n\n#\\0001\n"
"; Test error \"delimiter { is not allowed in #!r6rs mode\"\n\n#!r6rs #\\0{\n"
"; Test error \"invalid delimiter 2 for boolean\"\n\n#t2\n"
"; Test error \"invalid delimiter 2 for boolean\"\n\n#true2\n"
"; Test error \"invalid delimiter 3 for boolean\"\n\n#f3\n"
"; Test error \"invalid delimiter 3 for boolean\"\n\n#false3\n"
"; Test error \"invalid boolean\"\n\n#travis"
"; Test error \"invalid boolean\"\n\n#FALSIFY"
;; NOTE: there's no "delimiter not allowed in #!r6rs mode" test for r7rs-style booleans because they are not r6rs!
"; Test error \"#!eof syntax not allowed in #!r6rs mode\"\n\n#!r6rs #!eof\n"
"; Test error \"#!bwp syntax not allowed in #!r6rs mode\"\n\n#!r6rs #!bwp\n"
"; Test error \"#vfx(...) fxvector syntax not allowed in #!r6rs mode\"\n\n#!r6rs '#vfx(1 2 3)\n"
Expand All @@ -1873,7 +1909,12 @@
"; Test error \"123# number syntax not allowed in #!r6rs mode\"\n\n#!r6rs 123#\n"
"; Test error \"#x1/2e2 number syntax not allowed in #!r6rs mode\"\n\n#!r6rs 1/2e2\n"
"; Test error \"#x.3 number syntax not allowed in #!r6rs mode\"\n\n#!r6rs #x.3\n"

"; Test error \"alternative boolean syntax not allowed in #!r6rs mode\"\n\n#!r6rs #true\n"
"; Test error \"alternative boolean syntax not allowed in #!r6rs mode\"\n\n#!r6rs #True\n"
"; Test error \"alternative boolean syntax not allowed in #!r6rs mode\"\n\n#!r6rs #TRUE\n"
"; Test error \"alternative boolean syntax not allowed in #!r6rs mode\"\n\n#!r6rs #false\n"
"; Test error \"alternative boolean syntax not allowed in #!r6rs mode\"\n\n#!r6rs #False\n"
"; Test error \"alternative boolean syntax not allowed in #!r6rs mode\"\n\n#!r6rs #FALSE\n"
; following tests adapted from the read0 benchmark distributed by Will
; Clinger, which as of 08/08/2009 appears to be in the public domain,
; with no license, copyright notice, author name, or date.
Expand Down
24 changes: 12 additions & 12 deletions mats/patch-compile-0-f-t-f
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*** errors-compile-0-f-f-f 2020-02-28 19:40:51.000000000 -0800
--- errors-compile-0-f-t-f 2020-02-28 19:05:59.000000000 -0800
*** errors-compile-0-f-f-f 2021-04-23 10:12:28.440000000 -0400
--- errors-compile-0-f-t-f 2021-04-23 09:38:03.010000000 -0400
***************
*** 178,184 ****
3.mo:Expected error in mat dipa-letrec: "attempt to reference undefined variable a".
Expand Down Expand Up @@ -75,7 +75,7 @@
misc.mo:Expected error in mat cpletrec: "attempt to reference undefined variable b".
misc.mo:Expected error in mat cpletrec: "attempt to reference undefined variable a".
***************
*** 7436,7443 ****
*** 7499,7506 ****
7.mo:Expected error in mat bytes-allocated: "bytes-allocated: invalid space gnu".
7.mo:Expected error in mat error: "a: hit me!".
7.mo:Expected error in mat error: "f: n is 0".
Expand All @@ -84,7 +84,7 @@
record.mo:Expected error in mat record2: "invalid value 3 for foreign type double-float".
record.mo:Expected error in mat record2: "3 is not of type #<record type fudge>".
record.mo:Expected error in mat record2: "make-record-type: invalid field list ((immutable double-float a) . b)".
--- 7436,7443 ----
--- 7499,7506 ----
7.mo:Expected error in mat bytes-allocated: "bytes-allocated: invalid space gnu".
7.mo:Expected error in mat error: "a: hit me!".
7.mo:Expected error in mat error: "f: n is 0".
Expand All @@ -94,7 +94,7 @@
record.mo:Expected error in mat record2: "3 is not of type #<record type fudge>".
record.mo:Expected error in mat record2: "make-record-type: invalid field list ((immutable double-float a) . b)".
***************
*** 7445,7459 ****
*** 7508,7522 ****
record.mo:Expected error in mat type-descriptor: "invalid syntax (type-descriptor 3)".
record.mo:Expected error in mat type-descriptor: "type-descriptor: unrecognized record car".
record.mo:Expected error in mat record3: "variable set-fudge-a! is not bound".
Expand All @@ -110,7 +110,7 @@
record.mo:Expected error in mat record9: "record-reader: invalid input #f".
record.mo:Expected error in mat record9: "record-reader: invalid second argument fudge".
record.mo:Expected error in mat record9: "record-reader: invalid second argument fudge".
--- 7445,7459 ----
--- 7508,7522 ----
record.mo:Expected error in mat type-descriptor: "invalid syntax (type-descriptor 3)".
record.mo:Expected error in mat type-descriptor: "type-descriptor: unrecognized record car".
record.mo:Expected error in mat record3: "variable set-fudge-a! is not bound".
Expand All @@ -127,7 +127,7 @@
record.mo:Expected error in mat record9: "record-reader: invalid second argument fudge".
record.mo:Expected error in mat record9: "record-reader: invalid second argument fudge".
***************
*** 7466,7491 ****
*** 7529,7554 ****
record.mo:Expected error in mat record10: "read: unresolvable cycle constructing record of type #<record type bar> at char 3 of #<input port string>".
record.mo:Expected error in mat record16: "read: unresolvable cycle constructing record of type #<record type bazar> at char 3 of #<input port string>".
record.mo:Expected error in mat record16: "read: unresolvable cycle constructing record of type #<record type bazar> at char 3 of #<input port string>".
Expand All @@ -154,7 +154,7 @@
record.mo:Expected error in mat foreign-data: "foreign-alloc: 0 is not a positive fixnum".
record.mo:Expected error in mat foreign-data: "foreign-alloc: <int> is not a positive fixnum".
record.mo:Expected error in mat foreign-data: "foreign-alloc: -5 is not a positive fixnum".
--- 7466,7491 ----
--- 7529,7554 ----
record.mo:Expected error in mat record10: "read: unresolvable cycle constructing record of type #<record type bar> at char 3 of #<input port string>".
record.mo:Expected error in mat record16: "read: unresolvable cycle constructing record of type #<record type bazar> at char 3 of #<input port string>".
record.mo:Expected error in mat record16: "read: unresolvable cycle constructing record of type #<record type bazar> at char 3 of #<input port string>".
Expand Down Expand Up @@ -182,7 +182,7 @@
record.mo:Expected error in mat foreign-data: "foreign-alloc: <int> is not a positive fixnum".
record.mo:Expected error in mat foreign-data: "foreign-alloc: -5 is not a positive fixnum".
***************
*** 7616,7654 ****
*** 7683,7721 ****
record.mo:Expected error in mat record22: "invalid field specifier (immutable creepy q)".
record.mo:Expected error in mat record22: "invalid field specifier (immutable creepy q)".
record.mo:Expected error in mat record23: "make-record-type: cannot extend sealed record type #<record type foo>".
Expand Down Expand Up @@ -222,7 +222,7 @@
record.mo:Expected error in mat record?: "record?: 4 is not a record type descriptor".
record.mo:Expected error in mat record?: "record?: a is not a record type descriptor".
record.mo:Expected error in mat record?: "record?: #(1) is not a record type descriptor".
--- 7616,7654 ----
--- 7683,7721 ----
record.mo:Expected error in mat record22: "invalid field specifier (immutable creepy q)".
record.mo:Expected error in mat record22: "invalid field specifier (immutable creepy q)".
record.mo:Expected error in mat record23: "make-record-type: cannot extend sealed record type #<record type foo>".
Expand Down Expand Up @@ -263,7 +263,7 @@
record.mo:Expected error in mat record?: "record?: a is not a record type descriptor".
record.mo:Expected error in mat record?: "record?: #(1) is not a record type descriptor".
***************
*** 7663,7719 ****
*** 7730,7786 ****
record.mo:Expected error in mat r6rs-records-procedural: "make-record-constructor-descriptor: invalid protocol flimflam".
record.mo:Expected error in mat r6rs-records-procedural: "attempt to apply non-procedure not-a-procedure".
record.mo:Expected error in mat r6rs-records-procedural: "attempt to apply non-procedure spam".
Expand Down Expand Up @@ -321,7 +321,7 @@
record.mo:Expected error in mat r6rs-records-syntactic: "define-record-type: incompatible record type cpoint - different parent".
record.mo:Expected error in mat r6rs-records-syntactic: "define-record-type: incompatible record type cpoint - different parent".
record.mo:Expected error in mat r6rs-records-syntactic: "cannot extend define-record-type parent fratrat".
--- 7663,7719 ----
--- 7730,7786 ----
record.mo:Expected error in mat r6rs-records-procedural: "make-record-constructor-descriptor: invalid protocol flimflam".
record.mo:Expected error in mat r6rs-records-procedural: "attempt to apply non-procedure not-a-procedure".
record.mo:Expected error in mat r6rs-records-procedural: "attempt to apply non-procedure spam".
Expand Down
Loading

0 comments on commit 728813f

Please sign in to comment.