4198578702 2010-11-07 kinaba: /** 4198578702 2010-11-07 kinaba: * Authors: k.inaba 3464a035ec 2010-11-20 kinaba: * License: NYSL 0.9982 (http://www.kmonos.net/nysl/) 4198578702 2010-11-07 kinaba: * 4198578702 2010-11-07 kinaba: * Entry point for Polemy interpreter. 423f308350 2010-11-07 kinaba: */ 3464a035ec 2010-11-20 kinaba: module main; 36c517dfc4 2010-11-23 kinaba: import polemy.repl; 423f308350 2010-11-07 kinaba: import std.stdio; 7de80acfb8 2010-11-09 kinaba: import std.algorithm; 3464a035ec 2010-11-20 kinaba: import std.array; 3464a035ec 2010-11-20 kinaba: 3464a035ec 2010-11-20 kinaba: /// Advance args[] to point the argument list fed to the script. 3464a035ec 2010-11-20 kinaba: /// Returns the name of the source file to run, or returns "" if 3464a035ec 2010-11-20 kinaba: /// no filename was given. Also, returns to libs[] the list of 3464a035ec 2010-11-20 kinaba: /// library source to load. 077506b38c 2010-11-08 kinaba: 3464a035ec 2010-11-20 kinaba: string parseArgv(ref string[] args, out string[] libs) 077506b38c 2010-11-08 kinaba: { 3464a035ec 2010-11-20 kinaba: args.popFront(); 3464a035ec 2010-11-20 kinaba: 3464a035ec 2010-11-20 kinaba: while( !args.empty && args.front=="-l" ) { 3464a035ec 2010-11-20 kinaba: args.popFront(); 3464a035ec 2010-11-20 kinaba: if( !args.empty ) { 3464a035ec 2010-11-20 kinaba: libs ~= args.front(); 3464a035ec 2010-11-20 kinaba: args.popFront(); 3464a035ec 2010-11-20 kinaba: } 3464a035ec 2010-11-20 kinaba: } 3464a035ec 2010-11-20 kinaba: 3464a035ec 2010-11-20 kinaba: if( args.empty ) 3464a035ec 2010-11-20 kinaba: return ""; 3464a035ec 2010-11-20 kinaba: else { 3464a035ec 2010-11-20 kinaba: scope(exit) args.popFront; 3464a035ec 2010-11-20 kinaba: return args.front; 7de80acfb8 2010-11-09 kinaba: } 3464a035ec 2010-11-20 kinaba: } 7de80acfb8 2010-11-09 kinaba: 3464a035ec 2010-11-20 kinaba: /// Entry point. 3f6f41b558 2010-11-20 kinaba: 3464a035ec 2010-11-20 kinaba: void main( string[] args ) 3464a035ec 2010-11-20 kinaba: { 3464a035ec 2010-11-20 kinaba: string[] libs; 3464a035ec 2010-11-20 kinaba: string src = parseArgv(args, libs); 3f6f41b558 2010-11-20 kinaba: 36c517dfc4 2010-11-23 kinaba: auto r = new REPL(args); 3464a035ec 2010-11-20 kinaba: if( src.empty ) 3464a035ec 2010-11-20 kinaba: r.greet(); 3464a035ec 2010-11-20 kinaba: foreach(lb; libs) 3464a035ec 2010-11-20 kinaba: r.runFile(lb); 3464a035ec 2010-11-20 kinaba: if( src.empty ) 3464a035ec 2010-11-20 kinaba: r.replLoop(); 7de80acfb8 2010-11-09 kinaba: else 3464a035ec 2010-11-20 kinaba: r.runFile(src); 423f308350 2010-11-07 kinaba: }