Skip to content

Commit 305b3ab

Browse files
committed
if优化
1 parent bf34458 commit 305b3ab

File tree

14 files changed

+319
-434
lines changed

14 files changed

+319
-434
lines changed

src/main/antlr/mcfppParser.g4

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ statement
447447
: fieldDeclaration ';'
448448
| statementExpression ';'
449449
| ifStatement
450-
| forStatement
451450
| whileStatement
452451
| doWhileStatement ';'
453452
| ';'
@@ -494,38 +493,17 @@ ifStatement
494493
;
495494

496495
elseIfStatement
497-
: ELSE IF '('expression')' ifBlock
496+
: ELSE IF '('expression')' block
498497
;
499498

500499
elseStatement
501-
: ELSE ifBlock
500+
: ELSE block
502501
;
503502

504503
ifBlock
505504
: block
506505
;
507506

508-
forStatement
509-
: FOR '(' forControl ')' forBlock
510-
;
511-
512-
forBlock
513-
: block
514-
;
515-
516-
forControl
517-
: forInit ';' expression? ';' forUpdate
518-
;
519-
520-
forInit
521-
: (fieldDeclaration|statementExpression)?
522-
| (fieldDeclaration|statementExpression) (',' (fieldDeclaration|statementExpression))+
523-
;
524-
525-
forUpdate
526-
: statementExpression*
527-
;
528-
529507
whileStatement
530508
: WHILE '(' expression ')' whileBlock
531509
;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import top.mcfpp.annotations.MNIFunction;
44
import top.mcfpp.core.lang.JsonTextConcrete;
55
import top.mcfpp.core.lang.MCInt;
6+
import top.mcfpp.core.lang.MCIntConcrete;
67
import top.mcfpp.lib.ListChatComponent;
78
import top.mcfpp.lib.ScoreChatComponent;
89
import top.mcfpp.util.ValueWrapper;
@@ -11,8 +12,12 @@ public class MCIntData {
1112

1213
@MNIFunction(caller = "int", returnType = "text", override = true)
1314
public static void toText(MCInt caller, ValueWrapper<JsonTextConcrete> returnValue) {
15+
if(caller instanceof MCIntConcrete intConcrete){
16+
MCIntConcreteData.toText(intConcrete, returnValue);
17+
return;
18+
}
1419
var l = new ListChatComponent();
15-
l.getComponents().add(new ScoreChatComponent(caller));
20+
l.append(new ScoreChatComponent(caller));
1621
returnValue.setValue(new JsonTextConcrete(l, "re"));
1722
}
1823
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class MCStringConcreteData {
1515
@MNIFunction(caller = "string", returnType = "text", override = true)
1616
public static void toText(MCStringConcrete caller, ValueWrapper<JsonTextConcrete> returnValue) {
1717
var l = new ListChatComponent();
18-
l.getComponents().add(new PlainChatComponent(caller.getValue().getValue()));
18+
l.append(new PlainChatComponent(caller.getValue().getValue()));
1919
returnValue.setValue(new JsonTextConcrete(l, "re"));
2020
}
2121
}

src/main/kotlin/top/mcfpp/Project.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ object Project {
160160
//是否生成数据包
161161
config.noDatapack = jsonObject.getBooleanValue("noDatapack")
162162

163+
config.noComment = jsonObject.getBooleanValue("noComment")
164+
163165

164166
} catch (e: Exception) {
165167
LogProcessor.error("Error while reading project from file \"$path\"")

src/main/kotlin/top/mcfpp/ProjectConfig.kt

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

33
import top.mcfpp.command.CommentType
4-
import top.mcfpp.io.MCFPPFile
54
import java.nio.file.Path
65
import kotlin.io.path.Path
76

@@ -70,5 +69,10 @@ open class ProjectConfig(
7069
/**
7170
* 不生成数据包
7271
*/
73-
var noDatapack: Boolean = false
72+
var noDatapack: Boolean = false,
73+
74+
/**
75+
* 不生成注释
76+
*/
77+
var noComment: Boolean = false
7478
)

0 commit comments

Comments
 (0)