New Macro Syntax Proposal
Davidl
Davidl at 126.com
Wed Apr 25 19:52:05 PDT 2007
Obviously the one I posted yesterday is not easy for IDE to highlight
sub-language set
and also it lacks the power of parse different sub-language expressions. I
think the
goal of macro should be powerful enough to introduce a new sub language.
Then the macro
itself could be called mature.
Consider the following
macro MyPowerfulMacro = CODEGEN //indicate the backend gen code output
string
{
KeyWordList(CASE_INSENSITIVE) // this is for IDE highlight
//the design here doesn't pollute keyword we have now, KeyWordList,
Expression Backend all only take effect in macro expression
{
object, TOKEN.object,
end, TOKEN.end,
}
Expression
{
expdeclare ::= EXP.expdeclare(objid, objattr[])
TOKEN.object {( TOKEN.identifier:objid TOKEN.identifier:~objattr
TOKEN.colon TOKEN.object)
| (EXP.expdeclare:objexp) } TOKEN.end
}
Backend EXP.expdeclare(objid, objattr[])
{
CODEGEN ~= class "~objid.strinof)~"{;
foreach(k;objattr)
{
CODEGEN ~= "class "~k.stringof~"{}"
}
CODEGEN ~= "}"
}
}
More information about the Digitalmars-d
mailing list