22 Syntax object manipulation utilities
(require phc-toolkit/stx) | package: phc-toolkit |
procedure
(stx-pair? v) → Boolean
v : Any
procedure
(stx-car/c car-c) → (→ Any (U #f Result))
car-c : (→ Any Result)
procedure
(stx-cdr/c cdr-c) → (→ Any (U #f Result))
cdr-c : (→ Any Result)
procedure
(stx-e/c e-c) → (→ Any (U #f Result))
e-c : (→ Any Result)
Also equivalent to (λ (v) (e-c (stx-e v))).
Returns a contract which accepts any value accepted by e-c. The contract also accepts any value v for which syntax? returns true and (syntax-e v) is accepted by e-c.
type
(Stx-List? A)
procedure
(stx-list? v) → Boolean
v : Any
procedure
(stx-list/c l-c) → (→ Any (U #f Result))
l-c : (→ Any Result)
(λ (v) (and (stx-list? v) (l-c (stx->list v))))
Returns a contract which accepts any list accepted by l-c. The contract also accepts any value v for which stx-list? returns true and (stx->list v) is accepted by e-c.
procedure
(stx-null? v) → Boolean
v : Any
procedure
(stx-assoc id alist) → (U (Syntaxof (Pairof Identifier T)) #f)
id : Identifier alist : (Syntaxof (Listof (Syntaxof (Pairof Identifier T)))) (stx-assoc id alist) → (U (Syntaxof (Pairof Identifier T)) #f) id : Identifier alist : (Listof (Syntaxof (Pairof Identifier T))) (stx-assoc id alist) → (U (Pairof Identifier T) #f) id : Identifier alist : (Listof (Pairof Identifier T))
procedure
(identifier->string identifier) → String
identifier : Identifier (identifier→string identifier) → String identifier : Identifier
22.1 Transformers utilities
procedure
(make-rest-transformer tranformer-function)
→ (-> syntax? syntax?) tranformer-function : (-> syntax? syntax?)
(λ (stx) (syntax-case stx () [(_ . rest) (f #'rest)]))
procedure
(make-id+call-transformer result) → (-> syntax? syntax?)
result : syntax?
the given result, when it is called as an identifier macro
(result arg ...) where the arg ... are the macro’s arguments (except the macro identifier itself), when it is called as a regular macro.
It is a shorthand for:
(λ (stx) (syntax-case stx () [(_ . args) (quasisyntax/top-loc stx (#,result . args))] [id (identifier? #'id) result]))
procedure
(make-id+call-transformer-delayed result)
→ (-> syntax? syntax?) result : (-> syntax?)
22.2 Patching source locations
syntax
(quasisyntax/top-loc stx-expr quasitemplate)
In other words, this does a traversal of the syntax object and updates the source location of the traversed parts, but the traversal does not go within a part whose source file differs from that of the quasitemplate.
For example, in the following code, the source location of parts within user-code will not be updated (unless user-code originates from the same file as quasitemplate), but the source location of all other parts will be updated, including the begin identifier and its surrounding form (its surrounding "pair of parentheses"). In contrast, quasisyntax/loc would have updated only the topmost syntax object, i.e. the outermost "pair of parentheses" of the let form.
(λ (stx) (syntax-case stx () [(_ . user-code) (with-syntax ([bg #'(begin . user-code)]) (quasisyntax/top-loc stx (let () bg)))]))
syntax
(syntax/top-loc stx-expr quasitemplate)
syntax
(quasisyntax/whole-loc stx-expr quasitemplate)
In the following example, all parts of the syntax object which source file is the same as the macro will be updated, including those within user-code (e.g. if the user-code contains code generated by other macros from the same file.
(λ (stx) (syntax-case stx () [(_ . user-code) (with-syntax ([bg #'(begin . user-code)]) (quasisyntax/whole-loc stx (let () bg)))]))
This is usually not needed, as quasisyntax/top-loc would have updated the source location of 1, 2 and 3 and their surrounding syntax list (the "pair of parentheses" around them), since their surrounding syntax list comes from the same file as the macro:
(λ (stx) (syntax-case stx () [(_ . user-function) (quasisyntax/top-loc stx (user-function 1 2 3))]))
syntax
(syntax/whole-loc stx-expr quasitemplate)
22.3 Untyped versions of syntax object manipulation utilities
(require phc-toolkit/untyped/stx) | package: phc-toolkit |
syntax
procedure
(identifier->string identifier) → String
identifier : Identifier (identifier→string identifier) → String identifier : Identifier
syntax
syntax
syntax
syntax
syntax
syntax