From 23fccba08113d9bacc0a50e4925fbbda181d4d77 Mon Sep 17 00:00:00 2001 From: ben Date: Sun, 13 Dec 2015 03:54:52 -0500 Subject: [PATCH] [private] init --- private/README.md | 5 +++++ private/common.rkt | 12 ++++++++++++ regexp.rkt | 10 ++++------ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 private/README.md create mode 100644 private/common.rkt diff --git a/private/README.md b/private/README.md new file mode 100644 index 0000000..82e5bd0 --- /dev/null +++ b/private/README.md @@ -0,0 +1,5 @@ +private +=== + +Files that no law-abiding library user should `require`. +- `common.rkt` Helper functions common to a few macros. diff --git a/private/common.rkt b/private/common.rkt new file mode 100644 index 0000000..bad38e0 --- /dev/null +++ b/private/common.rkt @@ -0,0 +1,12 @@ +#lang racket/base + +(provide + expand-expr + ;; (-> Syntax Syntax) + ;; Call local expand for an expression context with an empty list of stop-ids +) + +;; ============================================================================= + +(define (expand-expr stx) + (local-expand stx 'expression '())) diff --git a/regexp.rkt b/regexp.rkt index 06ce30d..f5b4b39 100644 --- a/regexp.rkt +++ b/regexp.rkt @@ -27,6 +27,7 @@ racket/syntax syntax/id-table syntax/parse + trivial/private/common )) ;; ============================================================================= @@ -53,7 +54,7 @@ [g:id (syntax/loc #'g f)] [(_ pat-stx) - #:with pat-stx+ (regexp-expand #'pat-stx) + #:with pat-stx+ (expand-expr #'pat-stx) #:with (num-groups . T) (count-groups #'pat-stx+) (syntax-property #'(f pat-stx+) num-groups-key @@ -64,7 +65,7 @@ (define-syntax define-f: (syntax-parser [(_ name:id pat-stx) - #:with pat-stx+ (regexp-expand #'pat-stx) + #:with pat-stx+ (expand-expr #'pat-stx) #:with (num-groups . T) (count-groups #'pat-stx+) (free-id-table-set! id+num-groups #'name @@ -81,7 +82,7 @@ (define-syntax regexp-match: (syntax-parser [(f pat-stx arg* ...) - #:with pat-stx+ (regexp-expand #'pat-stx) + #:with pat-stx+ (expand-expr #'pat-stx) #:with (num-groups . T) (count-groups #'pat-stx+) #:with (index* ...) #`#,(for/list ([i (in-range (syntax-e #'num-groups))]) i) #'(let ([maybe-match (regexp-match pat-stx+ arg* ...)]) @@ -105,9 +106,6 @@ (format "Valid regexp pattern (contains unmatched ~a)" reason) str)) -(define-for-syntax (regexp-expand stx) - (local-expand stx 'expression '())) - (define-for-syntax (quoted-stx-value? stx) (and (syntax? stx)