Skip to content

Commit 54ee366

Browse files
committed
support nil in syntax
1 parent 6a2e79c commit 54ee366

5 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/main/java/com/lootfilters/lang/Lexer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class Lexer {
2323
put("true", Token.Type.TRUE);
2424
put("meta", Token.Type.META);
2525
put("rule", Token.Type.RULE);
26+
put("nil", Token.Type.NIL);
2627
put("if", Token.Type.IF);
2728
put("&&", Token.Type.OP_AND);
2829
put("||", Token.Type.OP_OR);

src/main/java/com/lootfilters/lang/Parser.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import static com.lootfilters.lang.Token.Type.LITERAL_INT;
4949
import static com.lootfilters.lang.Token.Type.LITERAL_STRING;
5050
import static com.lootfilters.lang.Token.Type.META;
51+
import static com.lootfilters.lang.Token.Type.NIL;
5152
import static com.lootfilters.lang.Token.Type.OP_AND;
5253
import static com.lootfilters.lang.Token.Type.OP_NOT;
5354
import static com.lootfilters.lang.Token.Type.OP_OR;
@@ -179,9 +180,9 @@ private void parseRule(boolean isTerminal, int sourceLine) {
179180
case "color":
180181
builder.textColor(assign[1].expectColor()); break;
181182
case "backgroundColor":
182-
builder.backgroundColor(assign[1].expectColor()); break;
183+
builder.backgroundColor(assign[1].expectColor(true)); break;
183184
case "borderColor":
184-
builder.borderColor(assign[1].expectColor()); break;
185+
builder.borderColor(assign[1].expectColor(true)); break;
185186
case "hidden":
186187
builder.hidden(assign[1].expectBoolean()); break;
187188
case "showLootbeam":
@@ -363,6 +364,13 @@ private Token[] parseAssignment() { // assignments do not support nested express
363364
private void parseIcon(DisplayConfig.Builder builder) {
364365
tokens.takeExpect(IDENTIFIER);
365366
tokens.takeExpect(ASSIGN);
367+
if (tokens.peek().is(NIL)) {
368+
tokens.takeExpect(NIL);
369+
tokens.takeExpect(STMT_END);
370+
builder.icon(null);
371+
return;
372+
}
373+
366374
var type = tokens.takeExpect(IDENTIFIER);
367375
var args = tokens.takeArgList();
368376
if (type.getValue().equals("Sprite")) {

src/main/java/com/lootfilters/lang/Token.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public enum Type {
1414
IF, APPLY, RULE,
1515
META,
1616
COLON, COMMA,
17-
TRUE, FALSE,
17+
TRUE, FALSE, NIL,
1818
IDENTIFIER,
1919
LITERAL_INT, LITERAL_STRING,
2020
ASSIGN,
@@ -53,7 +53,11 @@ public String expectString() {
5353
return value;
5454
}
5555

56-
public Color expectColor() {
56+
public Color expectColor(boolean allowNil) {
57+
if (allowNil && type == Type.NIL) {
58+
return null;
59+
}
60+
5761
if (type != Type.LITERAL_STRING) {
5862
throw new ParseException("unexpected non-string token", this);
5963
}
@@ -65,6 +69,10 @@ public Color expectColor() {
6569
return color;
6670
}
6771

72+
public Color expectColor() {
73+
return expectColor(false);
74+
}
75+
6876
public boolean expectBoolean() {
6977
switch (type) {
7078
case TRUE: return true;

src/main/java/com/lootfilters/lang/TokenStream.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public Token takeExpectLiteral() {
8383
var first = take();
8484
if (!first.is(Token.Type.LITERAL_INT)
8585
&& !first.is(Token.Type.LITERAL_STRING)
86+
&& !first.is(Token.Type.NIL)
8687
&& !first.is(Token.Type.TRUE)
8788
&& !first.is(Token.Type.FALSE)) {
8889
throw new ParseException("unexpected non-literal token", first);

src/main/java/com/lootfilters/model/SoundProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public static SoundProvider fromExpr(Token token) throws ParseException {
1717
return new SoundEffect(token.expectInt());
1818
case LITERAL_STRING:
1919
return new File(token.expectString());
20+
case NIL:
21+
return null;
2022
default:
2123
throw new ParseException("sound: unexpected token", token);
2224
}

0 commit comments

Comments
 (0)