And does anyone has tried to use parser combinators on the result of the
reader, within a macro?

On Fri, Jul 9, 2010 at 11:23 AM, Jeff Rose <ros...@gmail.com> wrote:

> Like some people mentioned, you can use a parsing library, but often
> times I don't think that's necessary if you are just creating a DSL.
> There are a couple of other strategies.
>
> One is you can use a series of nested macros that expand into a data
> structure.  In this way your DSL will sort of auto-transform into a
> nested data structure that you can then just operate on like regular
> data.  Here's what I mean, using a mini database DSL as an example:
>
> (defmacro table [name & body]
>  `{:type :table
>    :name (str (quote ~name))
>    :cols [...@body]})
>
> (defmacro col [name type]
>  `{:type :col
>    :name (str (quote ~name))
>    :data-type ~type})
>
> ; Allowing for specifications like this:
>
> (table users
>  (col email :string)
>  (col password :string))
>
> (Note: You can run this code to see the data structure it produces...)
>
> Alternatively, if you want to get rid of parenthesis or introduce new
> semantics, then you'll need to process the tokens yourself with some
> logic.  At a larger scale this is better done with a parser, but if
> you just need to support a special keyword here or there, it's pretty
> easy to include some simple logic in a macro to look at a symbol and
> do something different depending on what it is.  In general I try to
> keep the semantics inside normal function definitions though, and just
> use macros for restructuring.
>
> -Jeff
>
> On Jul 8, 8:52 pm, Nicolas Oury <nicolas.o...@gmail.com> wrote:
> > Dear all,
> >
> > I am trying to write a small Domain Specific Language using macro, and I
> > want the syntax of the args of the macro to be somehow "parsed" and
> > transformed.
> >
> > So, I have two questions:
> >
> > - Does anybody else does that? (except the infix calculus) Is there a
> > generic method for doing it? Or even better a library?
> > - I want to report syntax error from my macro expansion. Is there a way
> to
> > get the line (or even better the line/file and character) of the usage of
> a
> > macro being expanded?
> > That way I could have helpful error message....
> >
> > Best regards,
> >
> > Nicolas.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to