Artifact Content
Not logged in

Artifact f44d615cc4428107166d0a9dc13e317eeb2a257e


     1  /**
     2   * Authors: k.inaba
     3   * License: NYSL 0.9982 (http://www.kmonos.net/nysl/)
     4   *
     5   * Entry point for Polemy interpreter.
     6   */
     7  module main;
     8  import polemy.repl;
     9  import std.stdio;
    10  import std.algorithm;
    11  import std.array;
    12  
    13  /// Advance args[] to point the argument list fed to the script.
    14  /// Returns the name of the source file to run, or returns "" if
    15  /// no filename was given. Also, returns to libs[] the list of
    16  /// library source to load.
    17  
    18  string parseArgv(ref string[] args, out string[] libs)
    19  {
    20  	args.popFront();
    21  
    22  	while( !args.empty && args.front=="-l" ) {
    23  		args.popFront();
    24  		if( !args.empty ) {
    25  			libs ~= args.front();
    26  			args.popFront();
    27  		}
    28  	}
    29  
    30  	if( args.empty )
    31  		return "";
    32  	else {
    33  		scope(exit) args.popFront;
    34  		return args.front;
    35  	}
    36  }
    37  
    38  /// Entry point.
    39  
    40  void main( string[] args )
    41  {
    42  	string[] libs;
    43  	string   src = parseArgv(args, libs);
    44  
    45  	auto r = new REPL(args);
    46  	if( src.empty )
    47  		r.greet();
    48  	foreach(lb; libs)
    49  		r.runFile(lb);
    50  	if( src.empty )
    51  		r.replLoop();
    52  	else
    53  		r.runFile(src);
    54  }