Adam D. Ruppe <destructiona...@gmail.com> писал(а) в своём письме Fri, 12
Nov 2010 23:13:13 +0600:
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.
Looks nice, especially dhp. But if 2nd problem isn't solved there is no
point in fixing imports
void main(string[] args){
import std.stdio; // 1. will not compile
void main(string[] args){
writeln("hello");
}
main(args); // 2. this should be appended, hence anyway rdmd should
analyze
// if there is main()
}
--
Alexander