Refactored TokenType.NUMBER to LITERAL and added error hover infos for it

This commit is contained in:
bigguy345 committed 2025-12-27 00:08:12 +02:00
1 parent 026a3dc8d3
commit bc3e8cb28e
5 files changed
+11 -19

No files matched your search

@@ -895,8 +895,8 @@ public class ScriptDocument {
// Methods
markMethodDeclarations(marks);
// Numbers
addPatternMarks(marks, NUMBER_PATTERN, TokenType.NUMBER);
// Numbers and othe
addPatternMarks(marks, NUMBER_PATTERN, TokenType.LITERAL);
// Method calls (parse before variables so we can attach context)
markMethodCalls(marks);
@@ -1654,15 +1654,6 @@ public class ScriptDocument {
}
return TypeInfo.fromPrimitive("int");
}
if (expr.matches("-?\\d+\\.\\d*[fF]?")) {
if (expr.toLowerCase().endsWith("f")) {
return TypeInfo.fromPrimitive("float");
}
return TypeInfo.fromPrimitive("double");
}
if (expr.matches("-?\\d+\\.\\d*[dD]")) {
return TypeInfo.fromPrimitive("double");
}
// "this" keyword
if (expr.equals("this")) {
@@ -136,7 +136,7 @@ public class ScriptTextContainer extends JavaTextContainer {
if (type == noppes.npcs.client.gui.util.script.interpreter.TokenType.TYPE_DECL) return JavaTextContainer.TokenType.TYPE_DECL;
if (type == noppes.npcs.client.gui.util.script.interpreter.TokenType.METHOD_DECL) return JavaTextContainer.TokenType.METHOD_DECARE;
if (type == noppes.npcs.client.gui.util.script.interpreter.TokenType.METHOD_CALL) return JavaTextContainer.TokenType.METHOD_CALL;
if (type == noppes.npcs.client.gui.util.script.interpreter.TokenType.NUMBER) return JavaTextContainer.TokenType.NUMBER;
if (type == noppes.npcs.client.gui.util.script.interpreter.TokenType.LITERAL) return JavaTextContainer.TokenType.NUMBER;
if (type == noppes.npcs.client.gui.util.script.interpreter.TokenType.GLOBAL_FIELD) return JavaTextContainer.TokenType.GLOBAL_FIELD;
if (type == noppes.npcs.client.gui.util.script.interpreter.TokenType.LOCAL_FIELD) return JavaTextContainer.TokenType.LOCAL_FIELD;
if (type == noppes.npcs.client.gui.util.script.interpreter.TokenType.PARAMETER) return JavaTextContainer.TokenType.PARAMETER;
@@ -1,7 +1,5 @@
package noppes.npcs.client.gui.util.script.interpreter;
import noppes.npcs.client.ClientProxy;
/**
* Represents a single token in the source code with its type and metadata.
* Tokens are the atomic units of the syntax highlighting system.
@@ -62,8 +60,8 @@ public class Token {
return new Token(text, start, end, TokenType.STRING);
}
public static Token number(String text, int start, int end) {
return new Token(text, start, end, TokenType.NUMBER);
public static Token literal(String text, int start, int end) {
return new Token(text, start, end, TokenType.LITERAL);
}
public static Token typeReference(String text, int start, int end, TypeInfo info) {
@@ -36,7 +36,7 @@ public enum TokenType {
LOCAL_FIELD(0xFFFF55, 25), // local variables (yellow)
// Literals
NUMBER(0x777777, 40), // numeric literals
LITERAL(0x777777, 40), // numeric and boolean literals
// Default
VARIABLE(0xFFFFFF, 30), // generic variables
@@ -65,7 +65,7 @@ public enum TokenType {
public char toColorCode() {
switch (this) {
case COMMENT:
case NUMBER:
case LITERAL:
case UNUSED_IMPORT:
return '7'; // gray
case STRING:
@@ -125,10 +125,13 @@ public class TokenHoverInfo {
info.extractUndefinedInfo(token);
break;
case LITERAL:
if (info.hasErrors())
return info;
return null;
case KEYWORD:
case MODIFIER:
case STRING:
case NUMBER:
case COMMENT:
// These don't need hover info typically
return null;