diff --git a/xenomorph/xenomorph/scribblings/xenomorph.scrbl b/xenomorph/xenomorph/scribblings/xenomorph.scrbl index be546522..28e954ac 100644 --- a/xenomorph/xenomorph/scribblings/xenomorph.scrbl +++ b/xenomorph/xenomorph/scribblings/xenomorph.scrbl @@ -1651,7 +1651,7 @@ Generate an instance of @racket[x:reserved%] (or a subclass of @racket[x:reserve boolean?]{ Whether @racket[x] is something that can be used as a length argument with @racket[xenomorphic?] objects that have length. For instance, an @racket[x:list] or @racket[x:stream]. -The following values are deemed to be resolvable: any @racket[exact-nonnegative-integer?], any @racket[procedure?] that returns a @racket[exact-nonnegative-integer?], or an @racket[x:int?]. +The following values are deemed to be resolvable: any @racket[exact-nonnegative-integer?], an @racket[x:int?], or any @racket[procedure?] that takes one argument (= the parent object) returns a @racket[exact-nonnegative-integer?]. } @section{License & source code} diff --git a/xenomorph/xenomorph/test/bytes-test.rkt b/xenomorph/xenomorph/test/bytes-test.rkt index 4f99cee7..4cc59ff3 100644 --- a/xenomorph/xenomorph/test/bytes-test.rkt +++ b/xenomorph/xenomorph/test/bytes-test.rkt @@ -31,7 +31,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Buffer.coffee (test-case "bytes: should decode with parent key length" (parameterize ([current-input-port (open-input-bytes (bytes #xab #xff #x1f #xb6))]) - (define buf (x:bytes #:length 'len)) + (define buf (x:bytes #:length (λ (p) (hash-ref p 'len)))) (check-equal? (decode buf #:parent (hash 'len 3)) (bytes #xab #xff #x1f)) (check-equal? (decode buf #:parent (hash 'len 1)) (bytes #xb6)))) diff --git a/xenomorph/xenomorph/test/list-test.rkt b/xenomorph/xenomorph/test/list-test.rkt index 8a5eecab..2e0d5546 100644 --- a/xenomorph/xenomorph/test/list-test.rkt +++ b/xenomorph/xenomorph/test/list-test.rkt @@ -41,12 +41,12 @@ https://github.com/mbutterick/restructure/blob/master/test/Array.coffee (test-case "list: decode length from parent key" (parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))]) - (check-equal? (decode (x:list #:type uint8 #:length 'len) (current-input-port) #:parent (mhash 'len 4)) '(1 2 3 4)))) + (check-equal? (decode (x:list #:type uint8 #:length (λ (p) (hash-ref p 'len))) (current-input-port) #:parent (mhash 'len 4)) '(1 2 3 4)))) (test-case "list: decode byte count from parent key" (parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))]) - (check-equal? (decode (x:list #:type uint16be #:length 'len #:count-bytes #t) (current-input-port) #:parent (mhash 'len 4)) '(258 772)))) + (check-equal? (decode (x:list #:type uint16be #:length (λ (p) (hash-ref p 'len)) #:count-bytes #t) (current-input-port) #:parent (mhash 'len 4)) '(258 772)))) (test-case "list: decode length as number before array" diff --git a/xenomorph/xenomorph/test/string-test.rkt b/xenomorph/xenomorph/test/string-test.rkt index fc18e332..0faca60b 100644 --- a/xenomorph/xenomorph/test/string-test.rkt +++ b/xenomorph/xenomorph/test/string-test.rkt @@ -26,7 +26,7 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee (test-case "string: decode length from parent key" (parameterize ([current-input-port (open-input-bytes #"testing")]) - (check-equal? (decode (x:string 'len) (current-input-port) #:parent (mhash 'len 7)) "testing"))) + (check-equal? (decode (x:string (λ (p) (hash-ref p 'len))) (current-input-port) #:parent (mhash 'len 7)) "testing"))) (test-case "string: decode length as number before string" diff --git a/xenomorph/xenomorph/test/symbol-test.rkt b/xenomorph/xenomorph/test/symbol-test.rkt index fcc55823..327b2624 100644 --- a/xenomorph/xenomorph/test/symbol-test.rkt +++ b/xenomorph/xenomorph/test/symbol-test.rkt @@ -22,7 +22,7 @@ (test-case "symbol: decode length from parent key" (parameterize ([current-input-port (open-input-bytes #"testing")]) - (check-equal? (decode (x:symbol 'len) (current-input-port) #:parent (mhash 'len 7)) 'testing))) + (check-equal? (decode (x:symbol (λ (p) (hash-ref p 'len))) (current-input-port) #:parent (mhash 'len 7)) 'testing))) (test-case "symbol: decode length as number before symbol" diff --git a/xenomorph/xenomorph/test/vector-test.rkt b/xenomorph/xenomorph/test/vector-test.rkt index 8612f2ce..0d638f72 100644 --- a/xenomorph/xenomorph/test/vector-test.rkt +++ b/xenomorph/xenomorph/test/vector-test.rkt @@ -42,12 +42,12 @@ https://github.com/mbutterick/restructure/blob/master/test/Array.coffee (test-case "vector: decode length from parent key" (parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))]) - (check-equal? (decode (x:vector #:type uint8 #:length 'len) (current-input-port) #:parent (mhash 'len 4)) '#(1 2 3 4)))) + (check-equal? (decode (x:vector #:type uint8 #:length (λ (p) (hash-ref p 'len))) (current-input-port) #:parent (mhash 'len 4)) '#(1 2 3 4)))) (test-case "vector: decode byte count from parent key" (parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))]) - (check-equal? (decode (x:vector #:type uint16be #:length 'len #:count-bytes #t) (current-input-port) #:parent (mhash 'len 4)) '#(258 772)))) + (check-equal? (decode (x:vector #:type uint16be #:length (λ (p) (hash-ref p 'len)) #:count-bytes #t) (current-input-port) #:parent (mhash 'len 4)) '#(258 772)))) (test-case "vector: decode length as number before array" diff --git a/xenomorph/xenomorph/util.rkt b/xenomorph/xenomorph/util.rkt index 9807a20a..23414a62 100644 --- a/xenomorph/xenomorph/util.rkt +++ b/xenomorph/xenomorph/util.rkt @@ -14,7 +14,6 @@ [#false #false] [(? exact-nonnegative-integer?) x] [(? procedure? proc) (proc parent)] - [(? symbol? key) #:when parent (dict-ref parent key)] [(? x:int?) #:when input-port (decode x input-port)] [_ (raise-argument-error 'resolve-length "fixed-size argument" x)]))