File tree Expand file tree Collapse file tree 3 files changed +36
-5
lines changed
main/kotlin/top/mcfpp/antlr
test/kotlin/top/mcfpp/test Expand file tree Collapse file tree 3 files changed +36
-5
lines changed Original file line number Diff line number Diff line change 4
4
"id":"default",
5
5
"functions":[
6
6
{
7
- "id":"generateSequence ",
7
+ "id":"generateSequenceDoWhile ",
8
8
"normalParams":[
9
9
10
10
],
15
15
]
16
16
},
17
17
{
18
- "id":"_while_1721ca59-7dd8-4e3b-b146-190ad749a4f2 ",
18
+ "id":"_dowhile_78ddf9e4-56ed-4439-93bc-bceb4e47f9ec ",
19
19
"normalParams":[
20
20
21
21
],
26
26
]
27
27
},
28
28
{
29
- "id":"expression_67b9dd31-2e5e-4873-a1a3-f4b5f0da11e2 ",
29
+ "id":"_dowhile_de4d3e61-9c4a-4c3f-81ae-3e7decf37e3b ",
30
30
"normalParams":[
31
31
32
32
],
37
37
]
38
38
},
39
39
{
40
- "id":"_while_block_4b041b7f-b519-423e-82cf-f816f0d548a3 ",
40
+ "id":"expression_52569370-85ad-4996-bbe1-8b209ead925a ",
41
41
"normalParams":[
42
42
43
43
],
Original file line number Diff line number Diff line change @@ -699,7 +699,8 @@ open class McfppImVisitor: mcfppParserBaseVisitor<Any?>() {
699
699
Project .ctx = ctx
700
700
// 调用完毕,将子函数的栈销毁
701
701
Function .addCommand(" data remove storage mcfpp:system " + Project .config.defaultNamespace + " .stack_frame[0]" )
702
- // 调用完毕,将子函数的栈销毁
702
+ // 返回1
703
+ Function .addCommand(" return 1" )
703
704
Function .currFunction = Function .currFunction.parent[0 ]
704
705
Function .addCommand(" #do while end" )
705
706
}
@@ -919,8 +920,10 @@ open class McfppImVisitor: mcfppParserBaseVisitor<Any?>() {
919
920
Function .addCommand(" #" + ctx.text)
920
921
// return语句
921
922
if (ctx.BREAK () != null ){
923
+ // break,完全跳出while
922
924
Function .addCommand(" return 0" )
923
925
}else {
926
+ // continue,跳过当次
924
927
Function .addCommand(" return 1" )
925
928
}
926
929
Function .currFunction.isReturned = true
Original file line number Diff line number Diff line change @@ -39,4 +39,32 @@ class LogicStatementTest {
39
39
""" .trimIndent()
40
40
MCFPPStringTest .readFromString(test, " D:\\ .minecraft\\ saves\\ MCFPP Studio\\ datapacks" )
41
41
}
42
+
43
+ @Test
44
+ fun doWhileTest () {
45
+ val test =
46
+ """
47
+ func generateSequenceDoWhile(){
48
+ dynamic int i = 0;
49
+ do {
50
+ print(i);
51
+ i = i + 1;
52
+ } while(i < 10);
53
+ }
54
+ """ .trimIndent()
55
+ MCFPPStringTest .readFromString(test, " D:\\ .minecraft\\ saves\\ MCFPP Studio\\ datapacks" )
56
+ }
57
+
58
+ @Test
59
+ fun forTest () {
60
+ val test =
61
+ """
62
+ func generateSequenceFor(){
63
+ for(dynamic int i = 0; i < 10; i = i + 1){
64
+ print(i);
65
+ }
66
+ }
67
+ """ .trimIndent()
68
+ MCFPPStringTest .readFromString(test, " D:\\ .minecraft\\ saves\\ MCFPP Studio\\ datapacks" )
69
+ }
42
70
}
You can’t perform that action at this time.
0 commit comments