Is it possible to obtain textual representation of an arbitary code?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Jan 26 11:40:22 UTC 2018


On Friday, January 26, 2018 11:32:42 Mike Parker via Digitalmars-d-learn 
wrote:
> On Friday, 26 January 2018 at 11:18:21 UTC, Oleksii Skidan wrote:
> > I could imagine a mixin-based solution in D:
> > ```d
> > // Usage:
> > ASSERT!"a == b";
> > ```
> > But it seems a bit alien to me. First of all, it kind of
> > stringly-typed one. Secondly, neither IDEs nor advanced text
> > editors are able to figure out that the string contains actual
> > D code, and so neither syntax highlighting nor code assistance
> > work with this approach.
>
> Token strings are intended for this and editors *should*
> highlight them (don't know if any currently do):
>
> https://dlang.org/spec/lex.html#token_strings

So that's what they're called. I can never remember (though I rarely use
them either, since I actually prefer that strings be highlighted as strings
and not code even if they contain code). vim definitely highlights them as
code, and I would expect most editors that don't understand them to
highlight them as if they were code, since q{} looks like code. If anything,
it would take a text editor that understood D quite well to highlight it as
a string (though really, no editor should be doing that, since the main
point of using token strings is for them to be highlighted as code).

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list