Source code output

Jacob Carlborg doob at me.com
Wed Jul 17 08:33:10 PDT 2013


On 2013-07-17 16:13, Ary Borenszweig wrote:

> Since Descent used a port of the D compiler to Java, I think the same
> can be done by tweaking dmd. You have the generated AST after semantic
> analysis and you can easily output that. But of course you need to be
> able to convert the AST to string with correct indentation.
>
> In general, I think a compiler should *really* care about setting line
> and column numbers to AST nodes and assisting the user as much as
> possible, like providing a way to output the final representation of the
> program as a String.
>
> For example compiling this program with D:
>
> ---
> string foo() {
>    return "void bar() {\n  return 1 + 2\n}";
> }
>
> void main() {
>    mixin(foo());
> }
> ---
>
> gives this error:
>
> foo.d(7): Error: expression expected, not ')'
> foo.d(8): Error: found '}' when expecting ';' following statement
> foo.d(8): Error: found 'EOF' when expecting '}' following compound
> statement
> foo.d(7): Error: + has no effect in expression (1 + 2 + 0)
>
> Can you see where is the error?
>
> I'll show here some ideas which D can use, which we have implemented in
> Crystal.
> [Snip]

That's how error messages should look like :)

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list