stxclass: #:description takes expression now
svn: r13288
This commit is contained in:
parent
f2fb56d07f
commit
38d4b95da9
|
@ -63,16 +63,18 @@
|
||||||
(list (syntax-e x) value)))
|
(list (syntax-e x) value)))
|
||||||
#f)))
|
#f)))
|
||||||
|
|
||||||
(define-basic-syntax-class (static-of name pred)
|
(define-syntax-class (static-of name pred)
|
||||||
([value 0])
|
#:description name
|
||||||
(lambda (x name pred)
|
(basic-syntax-class
|
||||||
(let/ec escape
|
([value 0])
|
||||||
(define (bad) (escape #f))
|
(lambda (x name pred)
|
||||||
(if (identifier? x)
|
(let/ec escape
|
||||||
(let ([value (syntax-local-value x bad)])
|
(define (bad) (escape #f))
|
||||||
(unless (pred value) (bad))
|
(if (identifier? x)
|
||||||
(list value))
|
(let ([value (syntax-local-value x bad)])
|
||||||
(bad)))))
|
(unless (pred value) (bad))
|
||||||
|
(list x value))
|
||||||
|
(bad))))))
|
||||||
|
|
||||||
(define-basic-syntax-class struct-name
|
(define-basic-syntax-class struct-name
|
||||||
([descriptor 0]
|
([descriptor 0]
|
||||||
|
|
|
@ -13,13 +13,17 @@
|
||||||
(define-struct expc (stxclasses pairs? data literals)
|
(define-struct expc (stxclasses pairs? data literals)
|
||||||
#:transparent)
|
#:transparent)
|
||||||
|
|
||||||
|
(define (make-stxclass-expc scdyn)
|
||||||
|
(make-expc (list scdyn) #f null null))
|
||||||
|
|
||||||
(begin-for-syntax
|
(begin-for-syntax
|
||||||
(define certify (syntax-local-certifier))
|
(define certify (syntax-local-certifier))
|
||||||
(define (expectation-of-stxclass stxclass)
|
(define (expectation-of-stxclass stxclass args)
|
||||||
(if stxclass
|
(if stxclass
|
||||||
(with-syntax ([name (sc-name stxclass)]
|
(with-syntax ([name (sc-name stxclass)]
|
||||||
[desc (sc-description stxclass)])
|
[desc-var (sc-description stxclass)]
|
||||||
(certify #'(make-expc (list (make-scdyn 'name 'desc)) #f null null)))
|
[(arg ...) args])
|
||||||
|
(certify #'(make-stxclass-expc (make-scdyn 'name (desc-var arg ...)))))
|
||||||
#'#f))
|
#'#f))
|
||||||
|
|
||||||
(define (expectation-of-constants pairs? data literals)
|
(define (expectation-of-constants pairs? data literals)
|
||||||
|
|
|
@ -225,18 +225,19 @@
|
||||||
(define (parse:extpk vars fcs extpk failid)
|
(define (parse:extpk vars fcs extpk failid)
|
||||||
(match extpk
|
(match extpk
|
||||||
[(struct idpks (stxclass args pks))
|
[(struct idpks (stxclass args pks))
|
||||||
(with-syntax ([sub-parse-expr
|
(with-syntax ([var0 (car vars)]
|
||||||
(if stxclass
|
[(arg ...) args]
|
||||||
#`(#,(sc-parser-name stxclass) #,(car vars) #,@args)
|
[(arg-var ...) (generate-temporaries args)]
|
||||||
#`(list #,(car vars)))]
|
|
||||||
[var0 (car vars)]
|
|
||||||
[(r) (generate-temporaries #'(r))])
|
[(r) (generate-temporaries #'(r))])
|
||||||
#`(let ([r sub-parse-expr])
|
#`(let ([arg-var arg] ...)
|
||||||
(if (ok? r)
|
(let ([r #,(if stxclass
|
||||||
#,(parse:pks (cdr vars) (cdr fcs) (shift-pks:id pks #'r) failid)
|
#`(#,(sc-parser-name stxclass) #,(car vars) arg-var ...)
|
||||||
#,(fail failid (car vars)
|
#`(list #,(car vars)))])
|
||||||
#:pattern (expectation-of-stxclass stxclass)
|
(if (ok? r)
|
||||||
#:fc (car fcs)))))]
|
#,(parse:pks (cdr vars) (cdr fcs) (shift-pks:id pks #'r) failid)
|
||||||
|
#,(fail failid (car vars)
|
||||||
|
#:pattern (expectation-of-stxclass stxclass #'(arg-var ...))
|
||||||
|
#:fc (car fcs))))))]
|
||||||
[(struct cpks (pairpks datumpkss literalpkss))
|
[(struct cpks (pairpks datumpkss literalpkss))
|
||||||
(with-syntax ([var0 (car vars)]
|
(with-syntax ([var0 (car vars)]
|
||||||
[(dvar0) (generate-temporaries (list (car vars)))])
|
[(dvar0) (generate-temporaries (list (car vars)))])
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
(define-struct attr (name depth inner)
|
(define-struct attr (name depth inner)
|
||||||
#:transparent)
|
#:transparent)
|
||||||
|
|
||||||
;; RHSBase is stx (listof SAttr) boolean string/#f
|
;; RHSBase is stx (listof SAttr) boolean stx/#f
|
||||||
(define-struct rhs (orig-stx attrs transparent? description)
|
(define-struct rhs (orig-stx attrs transparent? description)
|
||||||
#:transparent)
|
#:transparent)
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@
|
||||||
;; rhs-directive-table
|
;; rhs-directive-table
|
||||||
(define rhs-directive-table
|
(define rhs-directive-table
|
||||||
(list (list '#:literals check-idlist)
|
(list (list '#:literals check-idlist)
|
||||||
(list '#:description check-string)
|
(list '#:description values)
|
||||||
(list '#:transparent)))
|
(list '#:transparent)))
|
||||||
|
|
||||||
;; parse-pattern : stx(Pattern) env number -> Pattern
|
;; parse-pattern : stx(Pattern) env number -> Pattern
|
||||||
|
|
|
@ -32,52 +32,6 @@
|
||||||
current-expression
|
current-expression
|
||||||
current-macro-name)
|
current-macro-name)
|
||||||
|
|
||||||
#|
|
|
||||||
(begin-for-syntax
|
|
||||||
(define (check-attrlist stx)
|
|
||||||
(syntax-case stx ()
|
|
||||||
[(form ...)
|
|
||||||
(let ([names (for/list ([s (syntax->list #'(form ...))])
|
|
||||||
(check-attr s)
|
|
||||||
(stx-car s))])
|
|
||||||
(check-duplicate-identifier names)
|
|
||||||
stx)]
|
|
||||||
[_
|
|
||||||
(raise-syntax-error 'define-syntax-class
|
|
||||||
"expected attribute table" stx)]))
|
|
||||||
(define stxclass-table
|
|
||||||
`((#:description check-string)
|
|
||||||
(#:attributes check-attrlist)))
|
|
||||||
(define (split-rhss rhss stx)
|
|
||||||
(define-values (chunks rest)
|
|
||||||
(chunk-kw-seq/no-dups rhss stxclass-table #:context stx))
|
|
||||||
(define (assq* x alist default)
|
|
||||||
(cond [(assq x alist) => cdr]
|
|
||||||
[else default]))
|
|
||||||
(values (cond [(assq '#:attributes chunks) => caddr]
|
|
||||||
[else null])
|
|
||||||
(cond [(assq '#:description chunks) => caddr]
|
|
||||||
[else #f])
|
|
||||||
rest)))
|
|
||||||
|
|
||||||
(define-syntax (define-syntax-class stx)
|
|
||||||
(syntax-case stx ()
|
|
||||||
[(define-syntax-class (name arg ...) . rhss)
|
|
||||||
(let-values ([(attrs description rhss) (split-rhss #'rhss stx)])
|
|
||||||
#`(begin (define-syntax name
|
|
||||||
(make sc
|
|
||||||
'name
|
|
||||||
'(arg ...)
|
|
||||||
'#,attrs
|
|
||||||
((syntax-local-value) #'parser)
|
|
||||||
'description))
|
|
||||||
(define parser
|
|
||||||
(rhs->parser name #,rhss (arg ...) #,stx))))]
|
|
||||||
[(define-syntax-class name . rhss)
|
|
||||||
(syntax/loc stx
|
|
||||||
(define-syntax-class (name) . rhss))]))
|
|
||||||
|#
|
|
||||||
|
|
||||||
(define-syntax (define-syntax-class stx)
|
(define-syntax (define-syntax-class stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(define-syntax-class (name arg ...) . rhss)
|
[(define-syntax-class (name arg ...) . rhss)
|
||||||
|
@ -90,8 +44,9 @@
|
||||||
'(arg ...)
|
'(arg ...)
|
||||||
(rhs-attrs the-rhs)
|
(rhs-attrs the-rhs)
|
||||||
((syntax-local-certifier) #'parser)
|
((syntax-local-certifier) #'parser)
|
||||||
(rhs-description the-rhs))))
|
#'description)))
|
||||||
(define parser (rhs->parser name rhss (arg ...) #,stx)))]
|
(define-values (parser description)
|
||||||
|
(rhs->parser+description name rhss (arg ...) #,stx)))]
|
||||||
[(define-syntax-class name . rhss)
|
[(define-syntax-class name . rhss)
|
||||||
(syntax/loc stx
|
(syntax/loc stx
|
||||||
(define-syntax-class (name) . rhss))]))
|
(define-syntax-class (name) . rhss))]))
|
||||||
|
@ -128,15 +83,18 @@
|
||||||
([attr-name attr-depth] ...)
|
([attr-name attr-depth] ...)
|
||||||
(let ([name parser-expr]) name)))]))
|
(let ([name parser-expr]) name)))]))
|
||||||
|
|
||||||
(define-syntax (rhs->parser stx)
|
(define-syntax (rhs->parser+description stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(rhs->parser name rhss (arg ...) ctx)
|
[(rhs->parser+description name rhss (arg ...) ctx)
|
||||||
(parameterize ((current-syntax-context #'ctx))
|
(parameterize ((current-syntax-context #'ctx))
|
||||||
(let ([rhs (parse-rhs #'rhss #f #'ctx)]
|
(let ([rhs (parse-rhs #'rhss #f #'ctx)]
|
||||||
[sc (syntax-local-value #'name)])
|
[sc (syntax-local-value #'name)])
|
||||||
(parse:rhs rhs
|
#`(values #,(parse:rhs rhs
|
||||||
(sc-attrs sc)
|
(sc-attrs sc)
|
||||||
(syntax->list #'(arg ...)))))]))
|
(syntax->list #'(arg ...)))
|
||||||
|
(lambda (arg ...)
|
||||||
|
#,(or (rhs-description rhs)
|
||||||
|
#'(symbol->string 'name))))))]))
|
||||||
|
|
||||||
(define-syntax (parse-sc stx)
|
(define-syntax (parse-sc stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
|
@ -237,3 +195,52 @@
|
||||||
(values x n)]
|
(values x n)]
|
||||||
[(list-rest _ _ rest)
|
[(list-rest _ _ rest)
|
||||||
(frontier->syntax rest)]))
|
(frontier->syntax rest)]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#|
|
||||||
|
(begin-for-syntax
|
||||||
|
(define (check-attrlist stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(form ...)
|
||||||
|
(let ([names (for/list ([s (syntax->list #'(form ...))])
|
||||||
|
(check-attr s)
|
||||||
|
(stx-car s))])
|
||||||
|
(check-duplicate-identifier names)
|
||||||
|
stx)]
|
||||||
|
[_
|
||||||
|
(raise-syntax-error 'define-syntax-class
|
||||||
|
"expected attribute table" stx)]))
|
||||||
|
(define stxclass-table
|
||||||
|
`((#:description check-string)
|
||||||
|
(#:attributes check-attrlist)))
|
||||||
|
(define (split-rhss rhss stx)
|
||||||
|
(define-values (chunks rest)
|
||||||
|
(chunk-kw-seq/no-dups rhss stxclass-table #:context stx))
|
||||||
|
(define (assq* x alist default)
|
||||||
|
(cond [(assq x alist) => cdr]
|
||||||
|
[else default]))
|
||||||
|
(values (cond [(assq '#:attributes chunks) => caddr]
|
||||||
|
[else null])
|
||||||
|
(cond [(assq '#:description chunks) => caddr]
|
||||||
|
[else #f])
|
||||||
|
rest)))
|
||||||
|
|
||||||
|
(define-syntax (define-syntax-class stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(define-syntax-class (name arg ...) . rhss)
|
||||||
|
(let-values ([(attrs description rhss) (split-rhss #'rhss stx)])
|
||||||
|
#`(begin (define-syntax name
|
||||||
|
(make sc
|
||||||
|
'name
|
||||||
|
'(arg ...)
|
||||||
|
'#,attrs
|
||||||
|
((syntax-local-value) #'parser)
|
||||||
|
'#,description))
|
||||||
|
(define parser
|
||||||
|
(rhs->parser name #,rhss (arg ...) #,stx))))]
|
||||||
|
[(define-syntax-class name . rhss)
|
||||||
|
(syntax/loc stx
|
||||||
|
(define-syntax-class (name) . rhss))]))
|
||||||
|
|#
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user