Преглед изворни кода

- Fix bug in TypeFormatter with optional types

- Added virtual modifier
- Optimized parsing of modifiers
-
Stan Hebben пре 6 година
родитељ
комит
79720b4165

+ 1
- 1
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java Прегледај датотеку

@@ -133,7 +133,7 @@ public class TypeFormatter implements ITypeVisitor<String>, GenericParameterBoun
133 133
 
134 134
 	@Override
135 135
 	public String visitOptional(OptionalTypeID optional) {
136
-		return optional.accept(this) + "?";
136
+		return optional.baseType.accept(this) + "?";
137 137
 	}
138 138
 	
139 139
 	private void formatTypeParameters(StringBuilder result, TypeParameter[] parameters) {

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/Modifiers.java Прегледај датотеку

@@ -22,6 +22,7 @@ public class Modifiers {
22 22
 	public static final int STATIC = 128;
23 23
 	public static final int PROTECTED = 256;
24 24
 	public static final int IMPLICIT = 512;
25
+	public static final int VIRTUAL = 1024;
25 26
 	
26 27
 	public static boolean isAbstract(int modifiers) {
27 28
 		return (modifiers & ABSTRACT) > 0;
@@ -42,4 +43,8 @@ public class Modifiers {
42 43
 	public static boolean isImplicit(int modifiers) {
43 44
 		return (modifiers & IMPLICIT) > 0;
44 45
 	}
46
+	
47
+	public static boolean isVirtual(int modifiers) {
48
+		return (modifiers & VIRTUAL) > 0;
49
+	}
45 50
 }

+ 1
- 0
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenStream.java Прегледај датотеку

@@ -44,6 +44,7 @@ public class ZSTokenStream extends TokenStream<ZSToken, ZSTokenType> {
44 44
 		KEYWORDS.put("static", K_STATIC);
45 45
 		KEYWORDS.put("protected", K_PROTECTED);
46 46
 		KEYWORDS.put("implicit", K_IMPLICIT);
47
+		KEYWORDS.put("virtual", K_VIRTUAL);
47 48
 		
48 49
 		KEYWORDS.put("val", K_VAL);
49 50
 		KEYWORDS.put("var", K_VAR);

+ 1
- 0
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java Прегледај датотеку

@@ -90,6 +90,7 @@ public enum ZSTokenType implements TokenType {
90 90
 	K_STATIC,
91 91
 	K_PROTECTED,
92 92
 	K_IMPLICIT,
93
+	K_VIRTUAL,
93 94
 	
94 95
 	K_VAL,
95 96
 	K_VAR,

+ 29
- 17
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java Прегледај датотеку

@@ -62,24 +62,36 @@ public class ParsedFile {
62 62
 		while (true) {
63 63
 			CodePosition position = tokens.peek().position;
64 64
 			int modifiers = 0;
65
-			while (true) {
66
-				if (tokens.optional(K_PUBLIC) != null) {
67
-					modifiers |= Modifiers.PUBLIC;
68
-				} else if (tokens.optional(K_PRIVATE) != null) {
69
-					modifiers |= Modifiers.PRIVATE;
70
-				} else if (tokens.optional(K_EXPORT) != null) {
71
-					modifiers |= Modifiers.EXPORT;
72
-				} else if (tokens.optional(K_ABSTRACT) != null) {
73
-					modifiers |= Modifiers.ABSTRACT;
74
-				} else if (tokens.optional(K_FINAL) != null) {
75
-					modifiers |= Modifiers.FINAL;
76
-				} else if (tokens.optional(K_PROTECTED) != null) {
77
-					modifiers |= Modifiers.PROTECTED;
78
-				} else if (tokens.optional(K_IMPLICIT) != null) {
79
-					modifiers |= Modifiers.IMPLICIT;
80
-				} else {
81
-					break;
65
+			outer: while (true) {
66
+				switch (tokens.peek().type) {
67
+					case K_PUBLIC:
68
+						modifiers |= Modifiers.PUBLIC;
69
+						break;
70
+					case K_PRIVATE:
71
+						modifiers |= Modifiers.PRIVATE;
72
+						break;
73
+					case K_EXPORT:
74
+						modifiers |= Modifiers.EXPORT;
75
+						break;
76
+					case K_ABSTRACT:
77
+						modifiers |= Modifiers.ABSTRACT;
78
+						break;
79
+					case K_FINAL:
80
+						modifiers |= Modifiers.FINAL;
81
+						break;
82
+					case K_PROTECTED:
83
+						modifiers |= Modifiers.PROTECTED;
84
+						break;
85
+					case K_IMPLICIT:
86
+						modifiers |= Modifiers.IMPLICIT;
87
+						break;
88
+					case K_VIRTUAL:
89
+						modifiers |= Modifiers.VIRTUAL;
90
+						break;
91
+					default:
92
+						break outer;
82 93
 				}
94
+				tokens.next();
83 95
 			}
84 96
 
85 97
 			if (tokens.optional(K_IMPORT) != null) {

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java Прегледај датотеку

@@ -457,7 +457,7 @@ public abstract class ParsedExpression {
457 457
 	}
458 458
 	
459 459
 	public final CodePosition position;
460
-
460
+	
461 461
 	public ParsedExpression(CodePosition position) {
462 462
 		this.position = position;
463 463
 	}

+ 0
- 15
ScriptingExample/scripts/enums.zs Прегледај датотеку

@@ -1,15 +0,0 @@
1
-enum TestEnum {
2
-	HELLO,
3
-	WORLD
4
-}
5
-
6
-enum TestEnum2 {
7
-	HELLO("Hello"),
8
-	WORLD("World");
9
-	
10
-	val value as string;
11
-	
12
-	this(value as string) {
13
-		this.value = value;
14
-	}
15
-}

Loading…
Откажи
Сачувај