Will macros just be syntactic sugar?
Jari-Matti Mäkelä
jmjmak at utu.fi.invalid
Wed Apr 25 11:55:28 PDT 2007
Davidl wrote:
> macro (Token... tokens)
> {
> static if (tokens[0].ID != Token.LParen)
> pragma(error, `( expected`);
> else static if (tokens[1].ID != Token.Identifier)
> pragma(error, `identifer expected`);
> else static if (tokens[2].ID != Token.RParen)
> pragma(error, ) expected`);
> else static if (tokens[3].toChars != `:=`)
> pragma(error, `:= expected`);
> static if (tokens[4].ID != Token.LBracket)
> pragma(error, `( expected`);
> else static if (tokens[5].ID != Token.Identifier)
> pragma(error, `identifer expected`);
> else static if (tokens[6].ID != Token.RBracket)
> pragma(error, ) expected`);
> else static if (tokens[7].ID != Token.Identifier)
> pragma(error, `identifer expected`);
> else static if (tokens[8].ID != Token.plus)
> pragma(error, `+ operator expected`);
> else static if (tokens[9].ID != Token.Identifier)
> pragma(error, `identifer expected`);
> alias token[1] arg0;
> alias token[5] arg1;
> alias token[7] arg2;
> alias token[9] arg3;
> arg0[arg1] = arg2 + arg3;
> }
>
> seems the above is more valuable.
Huh, that looks awful. This kind of code surely needs some pattern
matching magic. Should we add it to D 2.0 wishlist too.
More information about the Digitalmars-d
mailing list