Browse Source

Actually make preprocs work

Jared 5 years ago
parent
commit
aebbcfbc43
No account linked to committer's email address

+ 6
- 4
JavaIntegration/src/main/java/org/openzen/zencode/java/PreProcessor.java View File

8
 public class PreProcessor implements Predicate<ParsedFile> {
8
 public class PreProcessor implements Predicate<ParsedFile> {
9
     
9
     
10
     private final String name;
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
         this.name = name;
14
         this.name = name;
15
         this.call = call;
15
         this.call = call;
16
     }
16
     }
19
     public boolean test(ParsedFile parsedFile) {
19
     public boolean test(ParsedFile parsedFile) {
20
         try(BufferedReader reader = new BufferedReader(parsedFile.file.open())) {
20
         try(BufferedReader reader = new BufferedReader(parsedFile.file.open())) {
21
             if(reader.lines().anyMatch(line -> line.trim().startsWith("#" + name))) {
21
             if(reader.lines().anyMatch(line -> line.trim().startsWith("#" + name))) {
22
-                return call.get();
22
+                return true;
23
             } else {
23
             } else {
24
                 return false;
24
                 return false;
25
             }
25
             }
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 View File

96
 		CompilingPackage scriptPackage = new CompilingPackage(new ZSPackage(space.rootPackage, name), scriptModule);
96
 		CompilingPackage scriptPackage = new CompilingPackage(new ZSPackage(space.rootPackage, name), scriptModule);
97
 		
97
 		
98
 		List<ParsedFile> files = new ArrayList<>();
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
             ParsedFile parsed = ParsedFile.parse(scriptPackage, bracketParser, sources[i]);
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
                 files.add(parsed);
113
                 files.add(parsed);
112
             }
114
             }
113
-		}
115
+        }
114
 		
116
 		
115
 		SemanticModule[] dependencyModules = new SemanticModule[dependencies.length + 1];
117
 		SemanticModule[] dependencyModules = new SemanticModule[dependencies.length + 1];
116
 		dependencyModules[0] = space.getModule("stdlib");
118
 		dependencyModules[0] = space.getModule("stdlib");

Loading…
Cancel
Save