瀏覽代碼

Added compile override for ParsedExpressionArray and ParsedExpressionMap

Essentially they are functions that accept the parsedExpression and the compilescope.
They return either null or a PartialExpression.
If they dont return null then the used partialexpression will be used instead of whatever the parsedexpression wouldve compiled to
kindlich 5 年之前
父節點
當前提交
826b8a4a81
沒有發現已知的金鑰在資料庫的簽署中

+ 13
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionArray.java 查看文件

@@ -6,7 +6,10 @@
6 6
 
7 7
 package org.openzen.zenscript.parser.expression;
8 8
 
9
+import java.util.ArrayList;
9 10
 import java.util.List;
11
+import java.util.function.BiFunction;
12
+
10 13
 import org.openzen.zencode.shared.CodePosition;
11 14
 import org.openzen.zencode.shared.CompileException;
12 15
 import org.openzen.zencode.shared.CompileExceptionCode;
@@ -24,7 +27,9 @@ import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
24 27
  * @author Stanneke
25 28
  */
26 29
 public class ParsedExpressionArray extends ParsedExpression {
27
-	private final List<ParsedExpression> contents;
30
+    
31
+    public static final List<BiFunction<ParsedExpressionArray, ExpressionScope, IPartialExpression>> compileOverrides = new ArrayList<>(0);
32
+    public final List<ParsedExpression> contents;
28 33
 
29 34
 	public ParsedExpressionArray(CodePosition position, List<ParsedExpression> contents) {
30 35
 		super(position);
@@ -34,6 +39,13 @@ public class ParsedExpressionArray extends ParsedExpression {
34 39
 
35 40
 	@Override
36 41
 	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
42
+        
43
+        for(BiFunction<ParsedExpressionArray, ExpressionScope, IPartialExpression> compileOverride : compileOverrides) {
44
+            final IPartialExpression apply = compileOverride.apply(this, scope);
45
+            if(apply != null)
46
+                return apply;
47
+        }
48
+        
37 49
 		StoredType asBaseType = null;
38 50
 		StoredType asType = null;
39 51
 		boolean couldHintType = false;

+ 14
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMap.java 查看文件

@@ -8,6 +8,9 @@ package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import java.util.ArrayList;
10 10
 import java.util.List;
11
+import java.util.function.BiFunction;
12
+import java.util.function.Function;
13
+
11 14
 import org.openzen.zencode.shared.CodePosition;
12 15
 import org.openzen.zencode.shared.CompileException;
13 16
 import org.openzen.zencode.shared.CompileExceptionCode;
@@ -30,8 +33,11 @@ import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
30 33
  * @author Stanneke
31 34
  */
32 35
 public class ParsedExpressionMap extends ParsedExpression {
33
-	private final List<ParsedExpression> keys;
34
-	private final List<ParsedExpression> values;
36
+    
37
+    public static final List<BiFunction<ParsedExpressionMap, ExpressionScope, ? extends IPartialExpression>> compileOverrides = new ArrayList<>(0);
38
+    
39
+	public final List<ParsedExpression> keys;
40
+	public final List<ParsedExpression> values;
35 41
 
36 42
 	public ParsedExpressionMap(
37 43
 			CodePosition position,
@@ -45,6 +51,12 @@ public class ParsedExpressionMap extends ParsedExpression {
45 51
 
46 52
 	@Override
47 53
 	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
54
+        for(BiFunction<ParsedExpressionMap, ExpressionScope, ? extends IPartialExpression> compileOverride : compileOverrides) {
55
+            final IPartialExpression apply = compileOverride.apply(this, scope);
56
+            if(apply != null)
57
+                return apply;
58
+        }
59
+	    
48 60
 		StoredType usedHint = null;
49 61
 		List<StoredType> keyHints = new ArrayList<>();
50 62
 		List<StoredType> valueHints = new ArrayList<>();

Loading…
取消
儲存