dmt: Python-like indentation in D programming language

Witold Baryluk witold.baryluk+d at gmail.com
Fri Nov 19 22:35:06 UTC 2021


On Friday, 19 November 2021 at 10:03:00 UTC, bauss wrote:
>
> Isn't def redundant in this since D already declares types then 
> you can assume if it's not enum, template, mixin template, 
> class, struct or union then it must be a function if it also 
> end with (...):
>
> Like:
>
>     ```d
>     int foo():
>         return 10
>     ```
>
> You'd never be in doubt that foo was a function or that:
>
>     ```d
>     template Foo(T):
>         alias Foo = T
>     ```
>
> Foo in this case was a template.

Technically yes, but I do not have full proper parser or grammar,
to do the conversion in all possible cases.

The main issue is with the context:

`type name ` ... can be also a start of a variable with a lambda, 
even if it ends with `:`:

```d
auto x = delegate(int y):
    return y * y
```

The return type itself can be a complex template instantiation.

`F!(....) foo():`

Same with argument types, they might be templates (or maybe even 
mixins?).

Plus it does not necessarily ends with `(...):`, for example it 
can have attributes:

`... (...) pure nothrow @bar:`

Plus of course all the other things like `static`, `public`, 
`extern(...)`, ... at the front.

So yes, `dmt` is not perfect, but for now it still allows to use 
full feature set of D, and use simple rules for achieving these 
goals.

If the tool gains some popularity, there is certainly a possibly 
of adding a proper grammar and parser, and making `def` on 
functions optional. Proper parser will also help in few other 
places, like multi line signature definitions, comments in the 
middle of the multi line definition, enum definitions and array 
literals.



BTW.

I forgot to add to my initial post, that `dmt` generates the 
`#line` directives, making compile errors and warning from `dmd`, 
`gdc` and `ldc` point back exactly to the proper input `.dt` file 
and original line number in it.

And you can pass multiple file to `dmt` tool, including mix of 
`.dt` and non-`.dt` files (i.e. `.d`, `.o`) to link them all 
together by the compiler in expected fashion.


> Great project tho!

Thanks.




More information about the Digitalmars-d-announce mailing list