File: url-patterns.rkt

package info (click to toggle)
racket 7.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 125,432 kB
  • sloc: ansic: 258,980; pascal: 59,975; sh: 33,650; asm: 13,558; lisp: 7,124; makefile: 3,329; cpp: 2,889; exp: 499; python: 274; xml: 11
file content (57 lines) | stat: -rw-r--r-- 1,631 bytes parent folder | download | duplicates (11)
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
#lang racket/base
(require racket/match
         web-server/dispatch/coercion
         web-server/dispatch/bidi-match)

(define-syntax define-bidi-match-expander/coercions
  (syntax-rules ()
    [(_ id in-test? in out-test? out)
     (begin (define-coercion-match-expander in/m in-test? in)
            (define-coercion-match-expander out/m out-test? out)
            (define-bidi-match-expander id in/m out/m))]))

; number arg
(define string->number? (make-coerce-safe? string->number))
(define-bidi-match-expander/coercions number-arg
  string->number? string->number
  number? number->string)

; integer arg
(define (string->integer x)
  (define nx (string->number x))
  (if (integer? nx)
      nx
      (error 'string->integer "Not an integer string")))
(define string->integer? (make-coerce-safe? string->integer))
(define-bidi-match-expander/coercions integer-arg
  string->integer? string->integer
  integer? number->string)

; real arg
(define (string->real x)
  (define nx (string->number x))
  (if (real? nx)
      nx
      (error 'string->real "Not an real string")))
(define string->real? (make-coerce-safe? string->real))
(define-bidi-match-expander/coercions real-arg
  string->real? string->real
  real? number->string)

; string arg
(define-match-expander string->string/m
  (syntax-rules ()
    [(_ str) (? string? str)]))

(define-bidi-match-expander string-arg string->string/m string->string/m)

; symbol arg
(define-bidi-match-expander/coercions symbol-arg
  string? string->symbol
  symbol? symbol->string)

(provide number-arg
         integer-arg
         real-arg
         string-arg
         symbol-arg)