Browse Source

- Fix bug in TypeFormatter with optional types

- Added virtual modifier
- Optimized parsing of modifiers
-
Stan Hebben 6 years ago
parent
commit
79720b4165

+ 1
- 1
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java View File

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

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/Modifiers.java View File

22
 	public static final int STATIC = 128;
22
 	public static final int STATIC = 128;
23
 	public static final int PROTECTED = 256;
23
 	public static final int PROTECTED = 256;
24
 	public static final int IMPLICIT = 512;
24
 	public static final int IMPLICIT = 512;
25
+	public static final int VIRTUAL = 1024;
25
 	
26
 	
26
 	public static boolean isAbstract(int modifiers) {
27
 	public static boolean isAbstract(int modifiers) {
27
 		return (modifiers & ABSTRACT) > 0;
28
 		return (modifiers & ABSTRACT) > 0;
42
 	public static boolean isImplicit(int modifiers) {
43
 	public static boolean isImplicit(int modifiers) {
43
 		return (modifiers & IMPLICIT) > 0;
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 View File

44
 		KEYWORDS.put("static", K_STATIC);
44
 		KEYWORDS.put("static", K_STATIC);
45
 		KEYWORDS.put("protected", K_PROTECTED);
45
 		KEYWORDS.put("protected", K_PROTECTED);
46
 		KEYWORDS.put("implicit", K_IMPLICIT);
46
 		KEYWORDS.put("implicit", K_IMPLICIT);
47
+		KEYWORDS.put("virtual", K_VIRTUAL);
47
 		
48
 		
48
 		KEYWORDS.put("val", K_VAL);
49
 		KEYWORDS.put("val", K_VAL);
49
 		KEYWORDS.put("var", K_VAR);
50
 		KEYWORDS.put("var", K_VAR);

+ 1
- 0
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java View File

90
 	K_STATIC,
90
 	K_STATIC,
91
 	K_PROTECTED,
91
 	K_PROTECTED,
92
 	K_IMPLICIT,
92
 	K_IMPLICIT,
93
+	K_VIRTUAL,
93
 	
94
 	
94
 	K_VAL,
95
 	K_VAL,
95
 	K_VAR,
96
 	K_VAR,

+ 29
- 17
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java View File

62
 		while (true) {
62
 		while (true) {
63
 			CodePosition position = tokens.peek().position;
63
 			CodePosition position = tokens.peek().position;
64
 			int modifiers = 0;
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
 			if (tokens.optional(K_IMPORT) != null) {
97
 			if (tokens.optional(K_IMPORT) != null) {

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java View File

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

+ 0
- 15
ScriptingExample/scripts/enums.zs View File

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…
Cancel
Save