diff --git a/implementations/racket/preserves/preserves/pexprs.rkt b/implementations/racket/preserves/preserves/pexprs.rkt index 9686426..c902536 100644 --- a/implementations/racket/preserves/preserves/pexprs.rkt +++ b/implementations/racket/preserves/preserves/pexprs.rkt @@ -117,6 +117,7 @@ (match (peek-char in-port) [(or (? eof-object?) #\] #\> #\} #\)) *TRAILER-ANCHOR*] [_ (next)]))) + #:interpreter-annotation (lambda (line) (record 'r (list 'interpreter line))) #:on-hash (lambda (in-port source next parse-error* default) (match-lambda [#\{ (read-sequence 's in-port source next #\})] diff --git a/implementations/racket/preserves/preserves/read-text-generic.rkt b/implementations/racket/preserves/preserves/read-text-generic.rkt index d239a3f..ba16253 100644 --- a/implementations/racket/preserves/preserves/read-text-generic.rkt +++ b/implementations/racket/preserves/preserves/read-text-generic.rkt @@ -70,9 +70,10 @@ [(_ re pat) (app (lambda (v) (regexp-try-match re v)) pat)])) (define ((make-preserve-text-reader #:reader-name reader-name + #:interpreter-annotation interpreter-annotation + #:read-annotated-value read-annotated-value0 #:on-char on-char0 - #:on-hash on-hash0 - #:read-annotated-value read-annotated-value0) + #:on-hash on-hash0) in-port source read-syntax? decode-embedded0) (define read-annotations? read-syntax?) (define decode-embedded (or decode-embedded0 @@ -106,7 +107,7 @@ [#\# (match (next-char*) [(or #\space #\tab) (annotate-next-with (read-comment-line))] [(or #\newline #\return) (annotate-next-with "")] - [#\! (annotate-next-with `#s(interpreter ,(read-comment-line)))] + [#\! (annotate-next-with (interpreter-annotation (read-comment-line)))] [#\f (unless (delimiter-follows?) (parse-error* "Delimiter must follow #f")) #f] [#\t (unless (delimiter-follows?) (parse-error* "Delimiter must follow #t")) #t] [#\" (read-literal-binary)] diff --git a/implementations/racket/preserves/preserves/read-text.rkt b/implementations/racket/preserves/preserves/read-text.rkt index 1099232..fb17b89 100644 --- a/implementations/racket/preserves/preserves/read-text.rkt +++ b/implementations/racket/preserves/preserves/read-text.rkt @@ -15,6 +15,7 @@ (make-preserve-text-reader #:reader-name *reader-name* #:read-annotated-value (lambda (in-port source next parse-error*) next) + #:interpreter-annotation (lambda (line) `#s(interpreter ,line)) #:on-hash (lambda (in-port source next parse-error* default) (match-lambda [#\{ (sequence-fold in-port diff --git a/implementations/racket/preserves/preserves/tests/samples.pr b/implementations/racket/preserves/preserves/tests/samples.pr index 5bdb61b..ca05807 100644 --- a/implementations/racket/preserves/preserves/tests/samples.pr +++ b/implementations/racket/preserves/preserves/tests/samples.pr @@ -14,7 +14,7 @@ "In each test, let stripped = strip(annotatedValue)," " encodeBinary(·) produce canonical ordering and no annotations," " looseEncodeBinary(·) produce any ordering, but with annotations," - " annotatedBinary(·) produce canonical ordering, but with annotations," + " annotatedBinary(·) produce “canonical ordering”, but with annotations," " decodeBinary(·) include annotations," " encodeText(·) include annotations," " decodeText(·) include annotations," @@ -39,6 +39,10 @@ }> "Implementations may vary in their treatment of the difference between expectations" "21/22 and 31/32, depending on how they wish to treat end-of-stream conditions." + + "The idea of canonical-ordering-with-annotations is to encode, say, sets with their elements" + "in sorted order of their canonical annotationless binary encoding, but then actually" + "*serialized* with the annotations present." ]> diff --git a/implementations/racket/preserves/preserves/tests/test-pexprs.rkt b/implementations/racket/preserves/preserves/tests/test-pexprs.rkt index 074d6a3..a90afeb 100644 --- a/implementations/racket/preserves/preserves/tests/test-pexprs.rkt +++ b/implementations/racket/preserves/preserves/tests/test-pexprs.rkt @@ -138,6 +138,16 @@ PrecType = "PREC" / "PREC_LEFT" / "PREC_RIGHT" / "PREC_DYNAMIC"; ENDDOC ) +(define U #<pexprs P #:read-syntax? #t)) (newline)) (parameterize ((pretty-print-columns 10)) (write-pexprs (string->pexprs P #:read-syntax? #t)) (newline)) @@ -149,3 +159,5 @@ ENDDOC (parameterize ((pretty-print-columns 40)) (write-pexprs (string->pexprs S #:read-syntax? #t)) (newline)) (parameterize ((pretty-print-columns 40)) (write-pexprs (string->pexprs T #:read-syntax? #t)) (newline)) + +(parameterize ((pretty-print-columns 80)) (write-pexprs (string->pexprs U #:read-syntax? #t)) (newline)) diff --git a/preserves-expressions.md b/preserves-expressions.md index c5d4d68..96fc623 100644 --- a/preserves-expressions.md +++ b/preserves-expressions.md @@ -3,7 +3,7 @@ title: "P-expressions" --- Tony Garnock-Jones -February 2024. Version 0.3.1. +May 2024. Version 0.3.2. [text syntax]: preserves-text.html @@ -229,7 +229,7 @@ text-syntax encodings. # example of a comment at the end of a dictionary } # example of a comment at the end of the input file⌝ -= @ += @ [ value @"example of a comment at the end of a dictionary"