Bladeren bron

Actually make preprocs work

Jared 5 jaren geleden
bovenliggende
commit
aebbcfbc43
No account linked to committer's email address

+ 6
- 4
JavaIntegration/src/main/java/org/openzen/zencode/java/PreProcessor.java Bestand weergeven

@@ -8,9 +8,9 @@ import java.util.function.*;
8 8
 public class PreProcessor implements Predicate<ParsedFile> {
9 9
     
10 10
     private final String name;
11
-    private final Supplier<Boolean> call;
11
+    private final Predicate<ParsedFile> call;
12 12
     
13
-    public PreProcessor(String name, Supplier<Boolean> call) {
13
+    public PreProcessor(String name, Predicate<ParsedFile> call) {
14 14
         this.name = name;
15 15
         this.call = call;
16 16
     }
@@ -19,7 +19,7 @@ public class PreProcessor implements Predicate<ParsedFile> {
19 19
     public boolean test(ParsedFile parsedFile) {
20 20
         try(BufferedReader reader = new BufferedReader(parsedFile.file.open())) {
21 21
             if(reader.lines().anyMatch(line -> line.trim().startsWith("#" + name))) {
22
-                return call.get();
22
+                return true;
23 23
             } else {
24 24
                 return false;
25 25
             }
@@ -30,5 +30,7 @@ public class PreProcessor implements Predicate<ParsedFile> {
30 30
     }
31 31
     
32 32
     
33
-    
33
+    public Predicate<ParsedFile> getCall() {
34
+        return call;
35
+    }
34 36
 }

+ 14
- 12
JavaIntegration/src/main/java/org/openzen/zencode/java/ScriptingEngine.java Bestand weergeven

@@ -96,21 +96,23 @@ public class ScriptingEngine {
96 96
 		CompilingPackage scriptPackage = new CompilingPackage(new ZSPackage(space.rootPackage, name), scriptModule);
97 97
 		
98 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
-        }
107
-		for (int i = 0; i < sources.length; i++) {
108
-			sourceFileConsumer.accept(sources[i]);
99
+        
100
+        for(int i = 0; i < sources.length; i++) {
101
+            boolean loadFile = true;
102
+            sourceFileConsumer.accept(sources[i]);
109 103
             ParsedFile parsed = ParsedFile.parse(scriptPackage, bracketParser, sources[i]);
110
-            if(preProcessor.test(parsed)){
104
+            for(PreProcessor processor : preProcessors) {
105
+                if(processor.test(parsed)) {
106
+                    if(!processor.getCall().test(parsed)) {
107
+                        loadFile = false;
108
+                    }
109
+                    // should we stop once we find we can't load it or go on??
110
+                }
111
+            }
112
+            if(loadFile) {
111 113
                 files.add(parsed);
112 114
             }
113
-		}
115
+        }
114 116
 		
115 117
 		SemanticModule[] dependencyModules = new SemanticModule[dependencies.length + 1];
116 118
 		dependencyModules[0] = space.getModule("stdlib");

Laden…
Annuleren
Opslaan