<div class="gmail_extra">So from what I'm gathering the only way to share data with the reader and expander layer is to add the reader as a submodue in the main.rkt file. So I've done that and it works but now I have a new problem, provide doesn't seem to be providing anything. Here is an example main.rkt file that provides meta-count.<br>
<br><br>#lang racket<br>(provide (all-from-out racket)<br> meta-count)<br><br>(define meta-count 0)<br><br>(module* reader syntax/module-reader<br> racket<br> #:read meta-read<br> #:read-syntax meta-read-syntax<br>
(require (submod "." "..")<br> syntax/readerr)<br><br> (define (meta-read in)<br> (parameterize ([current-readtable (make-meta-readtable)])<br> (read in)))<br> <br> (define (meta-read-syntax src in)<br>
(parameterize ([current-readtable (make-meta-readtable)])<br> (read-syntax src in)))<br><br> (define (make-meta-readtable)<br> (make-readtable (current-readtable)<br> #\^ 'terminating-macro read-meta))<br>
(define read-meta<br> (case-lambda<br> [(ch in)<br> (rread (object-name in) in)]<br> [(ch in src line col pos)<br> (rread src in)]))<br> <br> (define (rread src in)<br>
(define-values (line col pos) (port-next-location in))<br> (let ([meta (regexp-match #rx"[^ (['`#]+" in)])<br> (if meta<br> (begin <br> (set! meta-count (add1 meta-count))<br>
(make-special-comment meta))<br> (raise-read-error "expected a metadata name" src line col pos 1)))))<br><br>So this simply counts the amount of metadata tags and provides the count.<br>However if I try this:<br>
#lang my-lang<br>^meta (+ ^meta1 1 2)<br>(display meta-count)<br><br><br>I should see 2 displayed but I get<br>"3<br>meta-count: unbound identifier in module"<br><br>I thought if you export data through provide in main.rkt you will be able to use it after specifying the #lang, why is this happenning?<br>
<br><br>>Maybe we should have a new `something' so that `#lang something' is<br>
>like `#lang reader', except that it looks for a `reader' submodule.<br><br>I think that would be awesome, that way you could specify your own mini-language or do preprocessing at the reader level by simply creating a reader submodule in the module.<br>
<br>>Special comments aren't stored by `read' or `read-syntax'; they're just<br>
>discarded. Creating a special comment has no side effect.<br><br>I don't understand why the the function is called (make-special-comment) then, why isn't it just called (discard) or (skip) or something. and why does it require a name as an argument if it isn't even going to do anything with it. I guess I'm still a little confused on how special comments are used.<br>
<br><br><div class="gmail_quote"><span dir="ltr"></span>>One way to attach metadata to a syntax object is to use a syntax<br>
>property. For example, the reader preserves the information that `[1<br>
>2]' is written qith suqare brackets by attaching a 'paren-shape<br>
>property to the result of `read-syntax'.<br><br>I think this could be useful, but adding a syntax property is something you can only do at the reader level right? Can you go back and alter a syntax property after it has been compiled? Is syntax information lost at a certain point?<br>
</div></div>