/usr/share/racket/collects/xml/path.rkt is in racket-common 6.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #lang racket/base
(require racket/contract
racket/match
racket/dict
racket/function
racket/list
xml)
(define keyword->symbol (compose string->symbol keyword->string))
(define (se-path/xexpr p x)
(match p
[(list)
(list x)]
[(list-rest (? symbol? s) r)
(match x
[(list-rest (? (curry equal? s)) rs)
(se-path/tag-body r rs)]
[_
empty])]
[_
empty]))
(define (se-path/tag-body p x)
(match p
[(list)
(match x
[(list) empty]
[(list-rest (list (list (? symbol?) (? string?)) ...) rs)
(se-path/tag-body p rs)]
[(? list?)
x]
[_
empty])]
[(list-rest (? symbol?) _)
(match x
[(list-rest (list (list (? symbol?) (? string?)) ...) rs)
(append-map (curry se-path/xexpr p) rs)]
[(? list?)
(append-map (curry se-path/xexpr p) x)]
[_
empty])]
[(list (? keyword? k))
(match x
[(list-rest (and attrs (list (list (? symbol?) (? string?)) ...)) rs)
(se-path/attr (keyword->symbol k) attrs)]
[_
empty])]
[_
empty]))
(define (se-path/attr k attrs)
(dict-ref attrs k empty))
(define (se-path*/list p x)
(append (se-path/xexpr p x)
(match x
[(list (? symbol? tag) (list (list (? symbol?) (? string?)) ...) rs ...)
(append-map (curry se-path*/list p) rs)]
[(list (? symbol? tag) rs ...)
(append-map (curry se-path*/list p) rs)]
[_
empty])))
(define (se-path* p x)
(match (se-path*/list p x)
[(list) #f]
[(list-rest f rs) f]))
(define se-path?
(match-lambda
[(list) #t]
[(list (? keyword?)) #t]
[(list-rest (? symbol?) l) (se-path? l)]
[_ #f]))
(provide/contract
[se-path? contract?]
[se-path*
(-> se-path? xexpr?
; XXX maybe this shouldn't be any/c
any/c)]
[se-path*/list
(-> se-path? xexpr?
; XXX see above
(listof any/c))])
|