Dialog compiler directives / conditional compilation

I was wondering if the Dialog compiler is capable of conditional compilation, such as #ifdef directives etc. I didn’t find this being mentioned in the documentation but only had a brief look.

1 Like

Yes, but not explicitely.

I think the only way is to put the conditional things in a separate file, and include it as needed. Say, if you want something only for the web version of the Å-machine, you can write a aa-web.dg file containing:

(style class @blabla)
    %% Some CSS only for the web.

%% A rule to check if we are compiling for the web.
(target is aa-web)

When targeting the Å-machine for the web, you would compile with this file; and without when not targeting the web.

And then, in you main source, you can simply check if (target is aa-web) succeeds. Normally, the compiler should be able to optimise the code away if it can make sure the rule always fails (by it not existing, for example).

The handling of source files is a thing I dislike in Dialog. I recommand using a Make/batch/shell/Python/whatever script (or a VS Code task) to handle all this.


I feared that’s the case. Thank you very much for your example code @Natrium729! I agree it’s not the most convenient way to handle of source files. One can of course craft a workaround in Python or VS Code, as you say, but this is definitely an area with room for improvement.