forked from mkhan45/RustScript
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRunner.java
More file actions
Latest commit
58 lines (54 loc) · 1.53 KB
/
Copy pathRunner.java
File metadata and controls
58 lines (54 loc) · 1.53 KB
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
importjava.io.IOException;
importjava.nio.file.Path;
importjava.nio.file.Paths;
importjava.util.Arrays;
importjava.util.List;
importcore.Interpreter;
importcore.util.FileHelper;
/**
* @author William Rågstad <william.ragstad@gmail.com>
*
* 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.
*
*/
publicclassRunner {
publicstaticvoidmain(String[] args) throwsException {
// args = new String[] { "test\\input9.2.rs" };
if (args.length == 0) {
System.out.println("Usage: Runner [file(s)]");
return;
}
run(Arrays.asList(args));
}
privatestaticStringcurrentDirectory;
publicstaticvoidrun(List<String> files) {
currentDirectory = System.getProperty("user.dir");
Interpreteri;
try {
i = newInterpreter();
} catch (Exceptione) {
System.out.println(e.getMessage());
return;
}
for (Stringfile : files) {
Stringsource;
PathfilePath = Paths.get(currentDirectory).resolve(file);
try {
source = FileHelper.readFile(filePath);
} catch (IOExceptione) {
e.printStackTrace();
continue;
}
try {
Stringp2 = filePath.getParent().normalize().toAbsolutePath().toString();
i.evalAll(source, p2); // Discard last the expressions value
} catch (Exceptione) {
System.out.println(e.getMessage());
return;
}
i.clear(); // New environment for each file.
}
}
}