Artifact f44d615cc4428107166d0a9dc13e317eeb2a257e
/**
* 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.
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);
}