The D Scripting Language

Adam D. Ruppe destructionator at gmail.com
Fri Nov 12 09:13:13 PST 2010


Alexander Malakhov wrote:
>  import std.stdio; // 1. will not compile

I wrote a little rund helper program, and a PHP style D interpreter
in another thread a couple days ago, that solves this by a simple
string scan.

http://arsdnet.net/dcode/rund.d
http://arsdnet.net/dcode/dhp.d

It scans the code byLine. If the line starts with "import", cut it out and move it
to the top of the final file outputted, above main.


This would break if you indented the import, or if it was in a string literal or
something, but there's a simple solution to that: don't do it!

Example of use:
$ rund
import std.math;

writeln(pow(4, 3));
<EOF>
64

======

$ dhp
<?d
import std.math; ?>  Four to the third power is <?= pow(4, 3) ?>!
<EOF>
  Four to the third power is 64!

=======

You can see the rule at work in the second example. <?d import std.math; ?>
wouldn't have been moved, so I just put a newline on it.


More information about the Digitalmars-d mailing list