Repair error wrt interpreter lines in pexpr text

This commit is contained in:
Tony Garnock-Jones 2024-05-02 16:21:47 +02:00
parent 23ba2e5a59
commit a33786e469
6 changed files with 25 additions and 6 deletions

View File

@ -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 #\})]

View File

@ -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)]

View File

@ -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

View File

@ -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."
]>
<TestCases {
annotation1: <Test #x"85 B103616263 B00109" @"abc" 9>

View File

@ -138,6 +138,16 @@ PrecType = "PREC" / "PREC_LEFT" / "PREC_RIGHT" / "PREC_DYNAMIC";
ENDDOC
)
(define U #<<ENDDOC
#!/example/of/a/shebang
{
key: value
# example of a comment at the end of a dictionary
}
# example of a comment at the end of the input file
ENDDOC
)
(parameterize ((pretty-print-columns 80)) (write-pexprs (string->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))

View File

@ -3,7 +3,7 @@ title: "P-expressions"
---
Tony Garnock-Jones <tonyg@leastfixedpoint.com>
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⌝
= @<interpreter "/example/of/a/shebang">
= @<r interpreter "/example/of/a/shebang">
[ <b
key <p |:|> value
@"example of a comment at the end of a dictionary" <a>