|
@@ -78,7 +78,7 @@ public class ScriptingEngine {
|
78
|
78
|
FunctionParameter[] scriptParameters,
|
79
|
79
|
String... dependencies) throws ParseException
|
80
|
80
|
{
|
81
|
|
- return createScriptedModule(name, sources, bracketParser, scriptParameters, Throwable::printStackTrace, System.out::println, sourceFile -> System.out.println("Loading " + sourceFile.getFilename()), dependencies);
|
|
81
|
+ return createScriptedModule(name, sources, bracketParser, scriptParameters, Throwable::printStackTrace, System.out::println, sourceFile -> System.out.println("Loading " + sourceFile.getFilename()), new PreProcessor[]{},dependencies);
|
82
|
82
|
}
|
83
|
83
|
|
84
|
84
|
public SemanticModule createScriptedModule(
|
|
@@ -89,15 +89,27 @@ public class ScriptingEngine {
|
89
|
89
|
Consumer<CompileException> compileExceptionConsumer,
|
90
|
90
|
Consumer<ValidationLogEntry> validatorErrorConsumer,
|
91
|
91
|
Consumer<SourceFile> sourceFileConsumer,
|
|
92
|
+ PreProcessor[] preProcessors,
|
92
|
93
|
String... dependencies) throws ParseException
|
93
|
94
|
{
|
94
|
95
|
Module scriptModule = new Module(name);
|
95
|
96
|
CompilingPackage scriptPackage = new CompilingPackage(new ZSPackage(space.rootPackage, name), scriptModule);
|
96
|
97
|
|
97
|
|
- ParsedFile[] files = new ParsedFile[sources.length];
|
|
98
|
+ List<ParsedFile> files = new ArrayList<>();
|
|
99
|
+ Predicate<ParsedFile> preProcessor = null;
|
|
100
|
+ for(PreProcessor processor : preProcessors) {
|
|
101
|
+ if(preProcessor == null) {
|
|
102
|
+ preProcessor = processor;
|
|
103
|
+ continue;
|
|
104
|
+ }
|
|
105
|
+ preProcessor = preProcessor.and(processor);
|
|
106
|
+ }
|
98
|
107
|
for (int i = 0; i < sources.length; i++) {
|
99
|
108
|
sourceFileConsumer.accept(sources[i]);
|
100
|
|
- files[i] = ParsedFile.parse(scriptPackage, bracketParser, sources[i]);
|
|
109
|
+ ParsedFile parsed = ParsedFile.parse(scriptPackage, bracketParser, sources[i]);
|
|
110
|
+ if(preProcessor.test(parsed)){
|
|
111
|
+ files.add(parsed);
|
|
112
|
+ }
|
101
|
113
|
}
|
102
|
114
|
|
103
|
115
|
SemanticModule[] dependencyModules = new SemanticModule[dependencies.length + 1];
|
|
@@ -109,7 +121,7 @@ public class ScriptingEngine {
|
109
|
121
|
SemanticModule scripts = ParsedFile.compileSyntaxToSemantic(
|
110
|
122
|
dependencyModules,
|
111
|
123
|
scriptPackage,
|
112
|
|
- files,
|
|
124
|
+ files.toArray(new ParsedFile[0]),
|
113
|
125
|
space,
|
114
|
126
|
scriptParameters,
|
115
|
127
|
compileExceptionConsumer);
|