On Saturday, 27 July 2013 at 22:27:35 UTC, Brian Schott wrote:
DScanner is a tool for analyzing D source code. It has the following features:

* Prints out a complete AST of a source file in XML format.
* Syntax checks code and prints warning/error messages
* Prints a listing of modules imported by a source file
* Syntax highlights code in HTML format
* Provides more meaningful "line of code" count than wc
* Counts tokens in a source file

The lexer/parser/AST are located in the "std/d" directory in the repository. These files should prove useful to anyone else working on D tooling.


Aside: the D grammar that I reverse-engineered can be located here: https://rawgithub.com/Hackerpilot/DGrammar/master/grammar.html

Dscanner looks like a good starting point for a code formatting tool (like gofmt). However, there seems to be a tradeoff with performance involved. For compilation you want a fast lexer and parser. For formatting you need to preserve comments, though.

For example, convert this from source to AST to source without losing the comments:

void /*hello*/ /*world*/ main () { }

Reply via email to