www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Mixins and comments

One use of mixins could be generating classes with methods and variables 
from a string definition (for example, to represent a table in a 
database, or an AST node in some language). In most languages this is 
done in two steps: some program generates the file and then it's 
compiled (*); in D it's done in one step.

However, in (*) the generated code usually includes documentation. In D 
currently this is not possible:

---
template GenStruct(char[] Name, char[] M1)
{
     const char[] GenStruct =
         "/** This comment for " ~ Name ~ " is invisible */"
         ~ "struct " ~ Name ~ "{ int " ~ M1 ~ "; }";
}

class S {
	
	/** This comment is visible */
	struct M {
	}

	// No comment for the generated struct Foo
	mixin(GenStruct!("Foo", "bar", "var"));

}
---

Is there any chance this could work in the future?
Feb 21 2007