Metaprogramming in D : Some Real-world Examples

Nick Sabalausky a at a.a
Thu Nov 12 04:14:45 PST 2009


"Nick Sabalausky" <a at a.a> wrote in message 
news:hdgt9q$vti$1 at digitalmars.com...
> >"Bill Baxter" <wbaxter at gmail.com> wrote in message 
> >news:mailman.337.1258023453.20261.digitalmars-d-announce at puremagic.com...
>>Hi Nick,
>
>>> === Compile-time checking on types with non-identifier strings ===
>>
>>That is kinda neat, I suppose you could even extend that to make the
>>list of valid tokens be a template parameter (either variadic, or
>>separated by some delimiter in one big string that then gets broken up
>>at runtime).  I guess you could pitch this as a baby step towards the
>>full-fledged compile-time parser.  Step 0 recognize valid tokens.
>>
>
> Interesting idea, yea. Might not be much help for the lib as I currently 
> have it though, since I'm just spitting out the static-style language 
> definitions from a tool that takes in a grammar and generates D code. 
> Certainly something to keep in mind for future expansion though.
>

One other idea I had for expanding on that NewStyle_StaticToken would be: 
Suppose a grammar had some sort of naming convention that, well, meant 
something within the context of that grammar. Then the application code 
could take something like "process(Token!("foo") token) {...}" and use 
compile-time string processing to do advanced pattern-matching on the 
token-name when selecting which token types to process a certain way (maybe 
it would have to be a static if or a templated instead of a basic function 
though). Not a fully fleshed-out idea, of course, but maybe the start of 
something. In fact, I think tango.util.Convert does something vaguely like 
that to look for conversion functions. 




More information about the Digitalmars-d-announce mailing list