Artifact 97a442948c980634d2fe1d36ebeb9dfc9db09245
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 /// TODO: use std.getopt
18
19 string parseArgv(ref string[] args, out string[] libs)
20 {
21 args.popFront();
22
23 while( !args.empty && args.front=="-l" ) {
24 args.popFront();
25 if( !args.empty ) {
26 libs ~= args.front();
27 args.popFront();
28 }
29 }
30
31 if( args.empty )
32 return "";
33 else {
34 scope(exit) args.popFront;
35 return args.front;
36 }
37 }
38
39 /// Entry point.
40
41 void main( string[] args )
42 {
43 string[] libs;
44 string src = parseArgv(args, libs);
45
46 auto r = new REPL(args);
47 if( src.empty )
48 r.greet();
49 foreach(lb; libs)
50 r.runFile(lb);
51 if( src.empty )
52 r.replLoop();
53 else
54 r.runFile(src);
55 }