syntax/parse: added docs for litset #:at kw, relaxed restriction on arg
This commit is contained in:
parent
9bc3457bbd
commit
fdede6f063
|
@ -1606,7 +1606,7 @@ A syntax class is integrable if
|
|||
|
||||
;; litset-directive-table
|
||||
(define litset-directive-table
|
||||
(cons (list '#:at check-identifier)
|
||||
(cons (list '#:at (lambda (stx ctx) stx))
|
||||
phase-directive-table))
|
||||
|
||||
;; var-pattern-directive-table
|
||||
|
|
|
@ -92,13 +92,18 @@ input's binding at phase @scheme[phase-expr].
|
|||
@specsubform/subs[(code:line #:literal-sets (literal-set ...))
|
||||
([literal-set literal-set-id
|
||||
(literal-set-id literal-set-option ...)]
|
||||
[literal-set-option (code:line #:at context-id)
|
||||
[literal-set-option (code:line #:at lctx)
|
||||
(code:line #:phase phase-expr)])
|
||||
#:contracts ([phase-expr (or/c exact-integer? #f)])]{
|
||||
|
||||
Many literals can be declared at once via one or more @tech{literal
|
||||
sets}, imported with the @scheme[#:literal-sets] option. See
|
||||
@tech{literal sets} for more information.
|
||||
|
||||
If the @racket[#:at] keyword is given, the lexical context of the
|
||||
@racket[lctx] term is used to determine which identifiers in the
|
||||
patterns are treated as literals; this option is useful primarily for
|
||||
macros that generate @racket[syntax-parse] expressions.
|
||||
}
|
||||
|
||||
@specsubform[(code:line #:conventions (conventions-id ...))]{
|
||||
|
|
|
@ -70,3 +70,20 @@
|
|||
(tcerr "litset, phase fail"
|
||||
(syntax-parse #'#%app #:literal-sets (litsk)
|
||||
[#%app (void)]))
|
||||
|
||||
;; ----
|
||||
|
||||
|
||||
(tcerr "litset, #:at"
|
||||
(let ()
|
||||
(define-literal-set lits #:phase 0
|
||||
(define lambda))
|
||||
(define-syntax-rule (getvar var stx)
|
||||
(syntax-parse stx #:literal-sets ([lits #:at here])
|
||||
[(lambda var _) #'var]))
|
||||
;; check that introduced lambda is a literal:
|
||||
(check-exn exn:fail? (lambda () (getvar x #'(a b c))))
|
||||
(check-equal? (syntax->datum (getvar x #'(lambda b c)))
|
||||
'(b))
|
||||
;; check that passed lambda is not a literal, but a pattern variable:
|
||||
(check-equal? (syntax->datum (getvar lambda #'(lambda b c))))))
|
||||
|
|
Loading…
Reference in New Issue
Block a user