forked from jeapostrophe/racket-langserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson-util.rkt
28 lines (26 loc) · 1.04 KB
/
json-util.rkt
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
#lang racket/base
(require (for-syntax racket/base
syntax/parse
syntax/parse/experimental/template)
racket/match
syntax/parse)
(define-syntax (define-json-expander stx)
(syntax-parse stx
[(_ name:id [key:id ctc:expr] ...+)
(with-syntax ([(key_ ...) (generate-temporaries #'(key ...))]
[(keyword ...)
(for/list ([k (syntax->datum #'(key ...))])
(string->keyword (symbol->string k)))]
[??-id (quote-syntax ??)])
(syntax/loc stx
(define-match-expander name
(λ (stx)
(syntax-parse stx
[(_ (~optional (~seq keyword key_)) ...)
(quasitemplate/loc stx (hash-table (??-id ['key (? ctc key_)]) ...))]))
(λ (stx)
(syntax-parse stx
[(_ (~optional (~seq keyword key_)) ...)
(syntax/loc stx
(make-hasheq (list (cons 'key key_) ...)))])))))]))
(provide define-json-expander)