Artifact Content
Not logged in

Artifact 97a442948c980634d2fe1d36ebeb9dfc9db09245


/**
 * Authors: k.inaba
 * License: NYSL 0.9982 (http://www.kmonos.net/nysl/)
 *
 * Entry point for Polemy interpreter.
 */
module main;
import polemy.repl;
import std.stdio;
import std.algorithm;
import std.array;

/// Advance args[] to point the argument list fed to the script.
/// Returns the name of the source file to run, or returns "" if
/// no filename was given. Also, returns to libs[] the list of
/// library source to load.
/// TODO: use std.getopt

string parseArgv(ref string[] args, out string[] libs)
{
	args.popFront();

	while( !args.empty && args.front=="-l" ) {
		args.popFront();
		if( !args.empty ) {
			libs ~= args.front();
			args.popFront();
		}
	}

	if( args.empty )
		return "";
	else {
		scope(exit) args.popFront;
		return args.front;
	}
}

/// Entry point.

void main( string[] args )
{
	string[] libs;
	string   src = parseArgv(args, libs);

	auto r = new REPL(args);
	if( src.empty )
		r.greet();
	foreach(lb; libs)
		r.runFile(lb);
	if( src.empty )
		r.replLoop();
	else
		r.runFile(src);
}