Skip to content

Commit 6028d61

Browse files
committed
重构逻辑语句,修复bool字面量不能被识别的问题
1 parent a5b082d commit 6028d61

25 files changed

+754
-569
lines changed

src/main/antlr/mcfppLexer.g4

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ LIST: 'list';
133133
MAP: 'map';
134134
DICT: 'dict';
135135

136+
137+
TRUE: 'true';
138+
FALSE: 'false';
139+
136140
VecType: VEC DigitSequence;
137141

138142
//Identifiers
@@ -186,6 +190,7 @@ NBTInt: IntConstant;
186190
NBTLong: IntConstant NBTLongSuffix;
187191
NBTFloat: FractionalConstant ExponentPart?;
188192
NBTDouble: (DigitSequence|FractionalConstant) ExponentPart? NBTDoubleSuffix;
193+
NBTBool: BooleanConstant;
189194

190195
FloatConstant
191196
: DigitSequence NBTFloatSuffix
@@ -202,8 +207,8 @@ RelativeValue
202207
;
203208

204209
BooleanConstant
205-
: 'true'
206-
| 'false'
210+
: TRUE
211+
| FALSE
207212
;
208213

209214
LineString: ('"' .*? '"' )|( '\'' .*? '\'' );

src/main/antlr/mcfppParser.g4

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ basicExpression
382382
;
383383
//初级表达式
384384
primary
385-
: var
386-
| range
385+
: range
387386
| value
387+
| var
388388
| THIS
389389
| SUPER
390390
;
@@ -588,7 +588,6 @@ functionReturnType
588588
value
589589
: coordinate
590590
| LineString
591-
| boolValue
592591
| multiLineStringLiteral
593592
| nbtValue
594593
| type
@@ -603,10 +602,6 @@ coordinateDimension
603602
: (RelativeValue | nbtInt | nbtFloat | nbtDouble)
604603
;
605604

606-
boolValue
607-
: BooleanConstant
608-
;
609-
610605
className
611606
: (Identifier ('.' Identifier)* ':')? classWithoutNamespace
612607
;
@@ -640,6 +635,7 @@ namespacePath
640635

641636
nbtValue
642637
: LineString
638+
| nbtBool
643639
| nbtByte
644640
| nbtShort
645641
| nbtInt
@@ -659,6 +655,7 @@ nbtInt: NBTInt;
659655
nbtLong: NBTLong;
660656
nbtFloat: NBTFloat;
661657
nbtDouble: NBTDouble;
658+
nbtBool: TRUE | FALSE;
662659

663660
nbtByteArray: NBT_BYTE_ARRAY_BEGIN nbtByte (',' nbtByte)* ']';
664661
nbtIntArray: NBT_INT_ARRAY_BEGIN nbtInt (',' nbtInt)* ']';

src/main/java/top/mcfpp/mni/NBTDictionaryConcreteData.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package top.mcfpp.mni;
22

3-
import net.querz.nbt.tag.CompoundTag;
43
import top.mcfpp.annotations.MNIFunction;
54
import top.mcfpp.core.lang.*;
6-
import top.mcfpp.core.lang.bool.MCBool;
7-
import top.mcfpp.core.lang.bool.MCBoolConcrete;
5+
import top.mcfpp.core.lang.bool.ScoreBool;
6+
import top.mcfpp.core.lang.bool.ScoreBoolConcrete;
87
import top.mcfpp.util.ValueWrapper;
98

109
public class NBTDictionaryConcreteData {
@@ -15,11 +14,11 @@ public static void clear(NBTDictionaryConcrete caller){
1514
}
1615

1716
@MNIFunction(normalParams = {"string key"}, caller = "dict", returnType = "bool")
18-
public static void containsKey(MCString key, NBTDictionaryConcrete caller, ValueWrapper<MCBool> re){
17+
public static void containsKey(MCString key, NBTDictionaryConcrete caller, ValueWrapper<ScoreBool> re){
1918
if(key instanceof MCStringConcrete keyC){
2019
String value = keyC.getValue().getValue();
2120
var nbt = caller.getValue();
22-
re.setValue(new MCBoolConcrete(value != null && nbt.containsKey(value), "return"));
21+
re.setValue(new ScoreBoolConcrete(value != null && nbt.containsKey(value), "return"));
2322
}else {
2423
caller.toDynamic(false);
2524
NBTDictionaryData.containsKey(key, caller, re);

src/main/java/top/mcfpp/mni/NBTDictionaryData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import top.mcfpp.command.Command;
55
import top.mcfpp.command.Commands;
66
import top.mcfpp.core.lang.*;
7-
import top.mcfpp.core.lang.bool.MCBool;
7+
import top.mcfpp.core.lang.bool.ScoreBool;
88
import top.mcfpp.model.function.Function;
99
import top.mcfpp.util.ValueWrapper;
1010

@@ -18,7 +18,7 @@ public static void clear(NBTDictionary caller){
1818
}
1919

2020
@MNIFunction(normalParams = {"string key"}, caller = "dict", returnType = "bool")
21-
public static void containsKey(MCString key, NBTDictionary caller, ValueWrapper<MCBool> re){
21+
public static void containsKey(MCString key, NBTDictionary caller, ValueWrapper<ScoreBool> re){
2222
if(key instanceof MCStringConcrete keyC){
2323
Function.Companion.addCommand(new Command("execute " +
2424
"store result score" + re.getValue().getIdentifier() + " " + re.getValue().getBoolObject() + " " +

src/main/java/top/mcfpp/mni/NBTListConcreteData.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import top.mcfpp.command.Command;
99
import top.mcfpp.command.Commands;
1010
import top.mcfpp.core.lang.*;
11-
import top.mcfpp.core.lang.bool.MCBool;
12-
import top.mcfpp.core.lang.bool.MCBoolConcrete;
11+
import top.mcfpp.core.lang.bool.ScoreBool;
12+
import top.mcfpp.core.lang.bool.ScoreBoolConcrete;
1313
import top.mcfpp.model.function.Function;
1414
import top.mcfpp.util.NBTUtil;
1515
import top.mcfpp.util.ValueWrapper;
@@ -218,10 +218,10 @@ public static void lastIndexOf(Var<?> e, NBTListConcrete caller, ValueWrapper<MC
218218
}
219219

220220
@MNIFunction(normalParams = {"E e"}, caller = "list", genericType = "E", returnType = "bool")
221-
public static void contains(Var<?> e, NBTListConcrete caller, ValueWrapper<MCBool> returnVar){
221+
public static void contains(Var<?> e, NBTListConcrete caller, ValueWrapper<ScoreBool> returnVar){
222222
if(e instanceof MCFPPValue eC){
223223
var contains = caller.getValue().contains(eC.getValue());
224-
returnVar.setValue(returnVar.getValue().assignedBy(new MCBoolConcrete(contains, UUID.randomUUID().toString())));
224+
returnVar.setValue(returnVar.getValue().assignedBy(new ScoreBoolConcrete(contains, UUID.randomUUID().toString())).toScoreBool());
225225
}else {
226226
caller.toDynamic(false);
227227
NBTListData.contains(e, caller, returnVar);

src/main/java/top/mcfpp/mni/NBTListData.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import top.mcfpp.command.Commands;
1010
import top.mcfpp.core.lang.*;
1111
import top.mcfpp.core.lang.MCFPPValue;
12-
import top.mcfpp.core.lang.bool.MCBool;
12+
import top.mcfpp.core.lang.bool.ScoreBool;
1313
import top.mcfpp.lib.NBTPath;
1414
import top.mcfpp.lib.SbObject;
1515
import top.mcfpp.lib.Storage;
@@ -26,7 +26,7 @@ public class NBTListData {
2626
static NBTBasedData list = new NBTBasedData("list.list");
2727
static NBTBasedData element = new NBTBasedData("list.element");
2828
static MCInt index = new MCInt("list.index");
29-
static MCBool contains = new MCBool("list.contains");
29+
static ScoreBool contains = new ScoreBool("list.contains");
3030

3131
static {
3232
list.setNbtPath(new NBTPath(new StorageSource(Storage.Companion.getMCFPP_SYSTEM().toString())).memberIndex("list.list"));
@@ -266,7 +266,7 @@ public static void lastIndexOf(Var<?> e, NBTList caller, ValueWrapper<MCInt> ret
266266
}
267267

268268
@MNIFunction(normalParams = {"E e"}, caller = "list", genericType = "E", returnType = "bool")
269-
public static void contains(Var<?> e, NBTList caller, ValueWrapper<MCBool> returnVar){
269+
public static void contains(Var<?> e, NBTList caller, ValueWrapper<ScoreBool> returnVar){
270270
var n = e.toNBTVar();
271271
element.assignedBy(n);
272272
element.assignedBy(caller);

src/main/java/top/mcfpp/mni/NBTMapConcreteData.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package top.mcfpp.mni;
22

3-
import net.querz.nbt.tag.ListTag;
43
import net.querz.nbt.tag.StringTag;
54
import top.mcfpp.annotations.MNIFunction;
65
import top.mcfpp.core.lang.*;
7-
import top.mcfpp.core.lang.bool.MCBool;
8-
import top.mcfpp.core.lang.bool.MCBoolConcrete;
6+
import top.mcfpp.core.lang.bool.ScoreBool;
7+
import top.mcfpp.core.lang.bool.ScoreBoolConcrete;
98
import top.mcfpp.util.ValueWrapper;
109

1110
public class NBTMapConcreteData {
@@ -19,18 +18,18 @@ public static void clear(NBTMapConcrete caller){
1918
}
2019

2120
@MNIFunction(normalParams = {"string key"}, caller = "dict", returnType = "bool")
22-
public static void containsKey(MCString key, NBTMapConcrete caller, ValueWrapper<MCBool> re){
21+
public static void containsKey(MCString key, NBTMapConcrete caller, ValueWrapper<ScoreBool> re){
2322
NBTListConcreteData.contains(key, (NBTListConcrete) caller.getKeyList(), re);
2423
}
2524

2625
@MNIFunction(normalParams = {""}, caller = "dict")
27-
public static void containsValue(Var<?> element, NBTMapConcrete caller, ValueWrapper<MCBool> re){
26+
public static void containsValue(Var<?> element, NBTMapConcrete caller, ValueWrapper<ScoreBool> re){
2827
NBTListConcreteData.contains(element.toNBTVar(), (NBTListConcrete) caller.getValueList(), re);
2928
}
3029

3130
@MNIFunction(caller = "dict", returnType = "bool")
32-
public static void isEmpty(NBTMapConcrete caller, ValueWrapper<MCBool> re){
33-
re.setValue(new MCBoolConcrete(((NBTListConcrete) (caller.getKeyList())).getValue().isEmpty(), "return"));
31+
public static void isEmpty(NBTMapConcrete caller, ValueWrapper<ScoreBool> re){
32+
re.setValue(new ScoreBoolConcrete(((NBTListConcrete) (caller.getKeyList())).getValue().isEmpty(), "return"));
3433
}
3534

3635
@MNIFunction(caller = "dict", returnType = "list")

src/main/java/top/mcfpp/mni/NBTMapData.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package top.mcfpp.mni;
22

33
import kotlin.NotImplementedError;
4-
import net.querz.nbt.tag.ListTag;
5-
import net.querz.nbt.tag.StringTag;
64
import top.mcfpp.annotations.MNIFunction;
75
import top.mcfpp.command.Command;
86
import top.mcfpp.core.lang.*;
9-
import top.mcfpp.core.lang.bool.MCBool;
10-
import top.mcfpp.core.lang.bool.MCBoolConcrete;
7+
import top.mcfpp.core.lang.bool.ScoreBool;
8+
import top.mcfpp.core.lang.bool.ScoreBoolConcrete;
119
import top.mcfpp.model.function.Function;
1210
import top.mcfpp.util.ValueWrapper;
1311

@@ -21,18 +19,18 @@ public static void clear(NBTMap caller){
2119
}
2220

2321
@MNIFunction(normalParams = {"string key"}, caller = "dict", returnType = "bool")
24-
public static void containsKey(MCString key, NBTMapConcrete caller, ValueWrapper<MCBool> re){
22+
public static void containsKey(MCString key, NBTMapConcrete caller, ValueWrapper<ScoreBool> re){
2523
NBTListData.contains(key, caller.getKeyList(), re);
2624
}
2725

2826
@MNIFunction(normalParams = {""}, caller = "dict")
29-
public static void containsValue(Var<?> element, NBTMapConcrete caller, ValueWrapper<MCBool> re){
27+
public static void containsValue(Var<?> element, NBTMapConcrete caller, ValueWrapper<ScoreBool> re){
3028
NBTListData.contains(element.toNBTVar(), caller.getValueList(), re);
3129
}
3230

3331
@MNIFunction(caller = "dict", returnType = "bool")
34-
public static void isEmpty(NBTMapConcrete caller, ValueWrapper<MCBool> re){
35-
re.setValue(new MCBoolConcrete(((NBTListConcrete) (caller.getKeyList())).getValue().isEmpty(), "return"));
32+
public static void isEmpty(NBTMapConcrete caller, ValueWrapper<ScoreBool> re){
33+
re.setValue(new ScoreBoolConcrete(((NBTListConcrete) (caller.getKeyList())).getValue().isEmpty(), "return"));
3634
}
3735

3836
@MNIFunction(caller = "dict", returnType = "list")

src/main/java/top/mcfpp/mni/minecraft/BossBarData.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
package top.mcfpp.mni.minecraft;
22

3-
import net.querz.nbt.io.SNBTUtil;
43
import top.mcfpp.annotations.MNIAccessor;
54
import top.mcfpp.annotations.MNIFunction;
65
import top.mcfpp.annotations.MNIMutator;
76
import top.mcfpp.command.Command;
87
import top.mcfpp.command.Commands;
98
import top.mcfpp.core.lang.*;
10-
import top.mcfpp.core.lang.bool.MCBool;
11-
import top.mcfpp.core.lang.bool.MCBoolConcrete;
9+
import top.mcfpp.core.lang.bool.ScoreBool;
10+
import top.mcfpp.core.lang.bool.ScoreBoolConcrete;
1211
import top.mcfpp.core.minecraft.PlayerVar;
1312
import top.mcfpp.model.function.Function;
1413
import top.mcfpp.util.FunctionUtil;
15-
import top.mcfpp.util.NBTUtil;
16-
import top.mcfpp.util.Utils;
1714
import top.mcfpp.util.ValueWrapper;
1815

1916
import java.util.Objects;
@@ -170,7 +167,7 @@ public static void setValue(DataTemplateObject bossbar, MCInt value){
170167
}
171168

172169
@MNIAccessor(name = "visible")
173-
public static void getVisible(DataTemplateObject bossbar, ValueWrapper<MCBool> returnValue){
170+
public static void getVisible(DataTemplateObject bossbar, ValueWrapper<ScoreBool> returnValue){
174171
var id = Objects.requireNonNull(bossbar.getMemberVarWithT("id", MCString.class));
175172
var command = new Command("execute store result score")
176173
.build(returnValue.getValue().nbtPath.toCommandPart(), true)
@@ -190,10 +187,10 @@ public static void getVisible(DataTemplateObject bossbar, ValueWrapper<MCBool> r
190187
}
191188

192189
@MNIMutator(name = "visible")
193-
public static void setVisible(DataTemplateObject bossbar, MCBool value){
190+
public static void setVisible(DataTemplateObject bossbar, ScoreBool value){
194191
var id = Objects.requireNonNull(bossbar.getMemberVarWithT("id", MCString.class));
195192
Command command;
196-
if(value instanceof MCBoolConcrete valueC){
193+
if(value instanceof ScoreBoolConcrete valueC){
197194
command = new Command("bossbar set");
198195
if(id instanceof MCStringConcrete idC){
199196
command.build(idC.getValue().getValue(), true);

0 commit comments

Comments
 (0)