static code generation

js.mdnq js_adddot+mdng at gmail.com
Wed Dec 12 19:32:36 PST 2012


On Monday, 10 December 2012 at 22:01:37 UTC, Ali Çehreli wrote:
> On 12/10/2012 01:52 PM, js.mdnq wrote:
>
> > I want to avoid having to wrap the code with "
> > " as it disables highlighting and possibly other
> features(intellisense,
> > etc...))
>
> The q{} syntax is supposed to help with that issue. Emacs 
> manages syntax highlighting correctly for the q{} strings:
>
> import std.stdio;
>
> void main()
> {
>     enum s = q{
>         writeln("hello world");
>     };
>
>     mixin (s);  // <-- s is a string
> }
>
> Ali

I think the issue I have with all this is that when you put code 
inside a string you lose a lot of compile time features AFAICT.

I can do

q{
    struct _name_
    {
       .... normal struct code ...
    }
} (but everything inside q is a string)

when I want to do

struct _name_
{
      .... normal struct code ...
}

in code. The first is in a string and the second isn't. The 
difference is that with q, I can parse the code and replace 
_name, for example, while in the second case I can't.

It makes it difficult to build up code by mixing stringified code 
and code. It's like, either you have to completely used 
stringified code or not use any at all.


For example, what if I mispell writeln? Sure I get an error but 
it's not at all the correct line number. But if I could use 
"actual code" that then the error should be normal.

>     enum s = q{
>         writelin("hello world");
>     };

in a large program, it could get confusing very quickly because 
essentially all errors will be pointing to oblivion.

This is why I want to all the user to supply actual code(and not 
stringified code) so that errors will show up properly.



More information about the Digitalmars-d-learn mailing list