> On Dec 9, 2018, at 8:20 PM, default.kra...@gmail.com wrote: > Is there an easy way to disallow certain characters in identifiers? I > realized it's not just dots I want to disallow, but also operators like + > which might be interpreted as infix in certain contexts.
Roughly, I imagine you'd want to 1) grab the input to `#%module-begin`, which is a tree-shaped syntax object 2) flatten it 3) search the list for forbidden identifiers (using `identifier?` and whatever patterns are forbidden) 4) report errors, or 5) if none, complete `#%module-begin` as usual. Like so: ;; "kapu.rkt" #lang racket (require (for-syntax racket/list)) (provide (except-out (all-from-out racket) #%module-begin) (rename-out [mb #%module-begin])) (define-syntax (mb stx) (syntax-case stx () [(_ . EXPRS) (let () (for ([id (in-list (filter identifier? (flatten (let loop ([stx #'EXPRS]) (define maybe-stxs (syntax->list stx)) (if maybe-stxs (map loop maybe-stxs) stx)))))] #:when (regexp-match #rx"\\.|\\+" (format "~a" (syntax->datum id)))) (raise-syntax-error 'mylang "invalid identifier name" (syntax->datum id))) #'(#%module-begin . EXPRS))])) ;; "test.rkt" #lang s-exp "kapu.rkt" (define foobar 42) (define foo.bar 42) (define foo+bar 42) > mylang: invalid identifier name in: foo.bar -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.