Ways to parse D code.

Jacob Carlborg doob at me.com
Thu Nov 26 16:08:57 UTC 2020


On 2020-11-25 17:27, Jan Hönig wrote:

> dmd has to do it somewhere as well. Although I don't know exactly where. 
> I do know ldc uses dmd's frontend for parsing.
> https://dlang.org/phobos/dmd_parse.html

Using DMD as a library will be most accurate and up to date. Because 
it's the same code as the compiler is using. Here's an example on how to 
use DMD to parse some code [1]. Here's some more advance usages [2].

[1] 
https://github.com/dlang/dmd/blob/b35572b07a6994385b6459a430674d32e9a97279/test/dub_package/frontend.d#L10-L24

[2] 
https://github.com/jacob-carlborg/dlp/blob/master/source/dlp/commands/infer_attributes.d#L61

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list