From 2a3d6d5c314967860079366ce3a1adbee2734529 Mon Sep 17 00:00:00 2001 From: Ryan Culpepper Date: Mon, 27 Feb 2012 04:02:24 -0700 Subject: [PATCH] syntax/parse: add attribute-prefix check to template form (template x.y) raises an error if x an attribute but x.y is not. --- collects/syntax/parse/experimental/template.rkt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/collects/syntax/parse/experimental/template.rkt b/collects/syntax/parse/experimental/template.rkt index 062c196287..eae4b53219 100644 --- a/collects/syntax/parse/experimental/template.rkt +++ b/collects/syntax/parse/experimental/template.rkt @@ -327,7 +327,18 @@ integers and integer vectors. v] [(template-metafunction? v) v] - [else #f]))) + [else + ;; id is a literal; check that for all x s.t. id = x.y, x is not a pattern variable + (for ([pfx (in-list (dotted-prefixes id))]) + (when (syntax-pattern-variable? (syntax-local-value pfx (lambda () #f))) + (wrong-syntax id "undefined nested attribute of attribute `~a'" (syntax-e pfx)))) + #f]))) + + (define (dotted-prefixes id) + (let* ([id-string (symbol->string (syntax-e id))] + [dot-locations (map car (regexp-match-positions* #rx"\\.[^.]" id-string))]) + (for/list ([loc (in-list dot-locations)]) + (datum->syntax id (string->symbol (substring id-string 0 loc)))))) (define (index-hash->vector hash [f values]) (let ([vec (make-vector (hash-count hash))])