forked from mkhan45/RustScript
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRunner.java
58 lines (54 loc) · 1.53 KB
/
Runner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import core.Interpreter;
import core.util.FileHelper;
/**
* @author William Rågstad <[email protected]>
*
* The Runner takes a set of input source code files as command line
* argument, and interprets them by expression. Even if one file fails
* to execute, the rest will.
*
*/
public class Runner {
public static void main(String[] args) throws Exception {
// args = new String[] { "test\\input9.2.rs" };
if (args.length == 0) {
System.out.println("Usage: Runner [file(s)]");
return;
}
run(Arrays.asList(args));
}
private static String currentDirectory;
public static void run(List<String> files) {
currentDirectory = System.getProperty("user.dir");
Interpreter i;
try {
i = new Interpreter();
} catch (Exception e) {
System.out.println(e.getMessage());
return;
}
for (String file : files) {
String source;
Path filePath = Paths.get(currentDirectory).resolve(file);
try {
source = FileHelper.readFile(filePath);
} catch (IOException e) {
e.printStackTrace();
continue;
}
try {
String p2 = filePath.getParent().normalize().toAbsolutePath().toString();
i.evalAll(source, p2); // Discard last the expressions value
} catch (Exception e) {
System.out.println(e.getMessage());
return;
}
i.clear(); // New environment for each file.
}
}
}