From cb3f2966789ead182db1ecbf7231e3a3b7a5fd38 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Mon, 8 Dec 2014 16:34:43 -0500 Subject: [PATCH] support this-syntax in syntax-parse, syntax-parser, etc. closes PR 14855 --- pkgs/racket-test/tests/stxparse/test.rkt | 23 +++++++++++++++++++ .../collects/syntax/parse/private/parse.rkt | 9 +++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/pkgs/racket-test/tests/stxparse/test.rkt b/pkgs/racket-test/tests/stxparse/test.rkt index a22c2b31b6..a1efa55ad5 100644 --- a/pkgs/racket-test/tests/stxparse/test.rkt +++ b/pkgs/racket-test/tests/stxparse/test.rkt @@ -2,6 +2,7 @@ (require rackunit syntax/parse syntax/parse/debug + syntax/parse/define "setup.rkt" (for-syntax syntax/parse)) @@ -576,3 +577,25 @@ (syntax->datum #'(let ([x 1] [y 2] [z 3]) (+ x y z)))) )) + +(test-case "this-syntax" + (let () + (define-syntax-class identity + [pattern _ + #:with stx this-syntax]) + (define stx #'(1 2 3)) + (syntax-parse stx + [x:identity + (check-eq? this-syntax stx) + (check-eq? #'x.stx stx)]) + ((syntax-parser + [x:identity + (check-eq? this-syntax stx) + (check-eq? #'x.stx stx)]) + stx) + (define-simple-macro (x . _) + #:with stx (syntax/loc this-syntax (void)) + stx) + (check-eq? (x) (void)) + )) + diff --git a/racket/collects/syntax/parse/private/parse.rkt b/racket/collects/syntax/parse/private/parse.rkt index a4fec508c6..aaf92f3102 100644 --- a/racket/collects/syntax/parse/private/parse.rkt +++ b/racket/collects/syntax/parse/private/parse.rkt @@ -161,7 +161,8 @@ [(syntax-parse stx-expr . clauses) (quasisyntax/loc stx (let ([x (datum->syntax #f stx-expr)]) - (parse:clauses x clauses body-sequence #,((make-syntax-introducer) stx))))])) + (with ([this-syntax x]) + (parse:clauses x clauses body-sequence #,((make-syntax-introducer) stx)))))])) (define-syntax (syntax-parser stx) (syntax-case stx () @@ -169,7 +170,8 @@ (quasisyntax/loc stx (lambda (x) (let ([x (datum->syntax #f x)]) - (parse:clauses x clauses body-sequence #,((make-syntax-introducer) stx)))))])) + (with ([this-syntax x]) + (parse:clauses x clauses body-sequence #,((make-syntax-introducer) stx))))))])) (define-syntax (syntax-parser/template stx) (syntax-case stx () @@ -177,7 +179,8 @@ (quasisyntax/loc stx (lambda (x) (let ([x (datum->syntax #f x)]) - (parse:clauses x clauses one-template ctx))))])) + (with ([this-syntax x]) + (parse:clauses x clauses one-template ctx)))))])) (define-syntax (define/syntax-parse stx) (syntax-case stx ()