From d01ea9737782aac9c62aaa5fb4ed9155876a6b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rgen=20Brandt?= Date: Tue, 26 Nov 2024 20:36:41 +0100 Subject: [PATCH 1/2] fix correspondence between location? and Location in typed/racket --- typed-racket-more/typed/xml.rkt | 10 ++++++--- typed-racket-test/unit-tests/xml-tests.rkt | 25 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 typed-racket-test/unit-tests/xml-tests.rkt diff --git a/typed-racket-more/typed/xml.rkt b/typed-racket-more/typed/xml.rkt index c14b0157f..ea55b0b39 100644 --- a/typed-racket-more/typed/xml.rkt +++ b/typed-racket-more/typed/xml.rkt @@ -18,12 +18,16 @@ (Pair Symbol (Pair (Listof XExpr-Attribute) (Listof XExpr))) (Pair Symbol (Listof XExpr)))) -(require/typed/provide xml +(require/typed xml [#:struct location ([line : (U False Exact-Nonnegative-Integer)] [char : (U False Exact-Nonnegative-Integer)] - [offset : Exact-Nonnegative-Integer]) - #:type-name Location] + [offset : Exact-Nonnegative-Integer])]) + +(define-type Location + (U location Symbol False)) + +(require/typed/provide xml [#:struct source ([start : Location] [stop : Location]) diff --git a/typed-racket-test/unit-tests/xml-tests.rkt b/typed-racket-test/unit-tests/xml-tests.rkt new file mode 100644 index 000000000..81e0e97de --- /dev/null +++ b/typed-racket-test/unit-tests/xml-tests.rkt @@ -0,0 +1,25 @@ +#lang typed/racket/base + +(module+ test + + (require typed/rackunit + "../../typed-racket-more/typed/xml.rkt") + + (let ([xml-p-i + (p-i #f #f 'xml "version=\"1.0\" encoding=\"UTF-8\"")]) + (check-eq? + (source-start xml-p-i) + #f) + (check-eq? + (source-stop xml-p-i) + #f)) + + (let ([xml-p-i + (p-i 'racket 'racket 'xml "version=\"1.0\" encoding=\"UTF-8\"")]) + (check-eq? + (source-start xml-p-i) + 'racket) + (check-eq? + (source-stop xml-p-i) + 'racket))) + From 858d6d46a17dbc0db52c0ea2c6072f1bda0e6d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rgen=20Brandt?= Date: Tue, 26 Nov 2024 20:41:31 +0100 Subject: [PATCH 2/2] maintain Location as struct type --- typed-racket-more/typed/xml.rkt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/typed-racket-more/typed/xml.rkt b/typed-racket-more/typed/xml.rkt index ea55b0b39..79786644a 100644 --- a/typed-racket-more/typed/xml.rkt +++ b/typed-racket-more/typed/xml.rkt @@ -18,19 +18,15 @@ (Pair Symbol (Pair (Listof XExpr-Attribute) (Listof XExpr))) (Pair Symbol (Listof XExpr)))) -(require/typed xml +(require/typed/provide xml [#:struct location ([line : (U False Exact-Nonnegative-Integer)] [char : (U False Exact-Nonnegative-Integer)] - [offset : Exact-Nonnegative-Integer])]) - -(define-type Location - (U location Symbol False)) - -(require/typed/provide xml + [offset : Exact-Nonnegative-Integer]) + #:type-name Location] [#:struct source - ([start : Location] - [stop : Location]) + ([start : (U Location Symbol False)] + [stop : (U Location Symbol False)]) #:type-name Source] [#:struct external-dtd ([system : String])