AST like coding syntax. Easy upgrade!

Idan Arye via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 6 17:34:17 PDT 2015


On Sunday, 6 September 2015 at 23:38:51 UTC, cym13 wrote:
> On Sunday, 6 September 2015 at 23:00:21 UTC, bitwise wrote:
>> On Sunday, 6 September 2015 at 22:37:16 UTC, cym13 wrote:
>>> On Sunday, 6 September 2015 at 21:16:18 UTC, Prudence wrote:
>>>>[...]
>>>
>>> There already is a kind of "code string":
>>>
>>>     interpret(q{
>>>          var a = 2;
>>>          var b += a;
>>>     });
>>>
>>> It doesn't do any kind of syntax check, but there again how 
>>> do you want to have syntax check for any language? The D 
>>> compiler is a D compiler, it can't support js syntax or 
>>> whatever.
>>
>> Many IDEs support multiple languages and can infer language 
>> automatically by syntax. It's probably much more difficult 
>> than it seems, but I suppose one of these IDEs could be made 
>> to parse and infer D token strings separately.
>
> Sure, but the support for that will be an external tool, it 
> doesn't have anything to do in the D compiler. q{} strings are 
> meant to be seen specially by editors, they won't highlight 
> them the same way for example, it is then the editor's job to 
> detect other languages if it wants to. D has done his job in 
> the matter.

Editors will have a hard time highlighting q{} strings 
differently, since they'll need to understand the semantics in 
order to know how the string will be parsed. Compare it to Ruby's 
heredoc, where the chosen terminator string can be used as an 
hint(https://github.com/joker1007/vim-ruby-heredoc-syntax). Sure, 
it may be just a convention, but an easily kept one that can make 
programmers' life easier.

You can't do that with D's q{} strings, unless you hard-code into 
the editor's relevant syntax file the templates that use them, 
just like the regular syntax of the language.


More information about the Digitalmars-d mailing list