parse a = b[c+d] + e[f*j] is ok

This commit is contained in:
lyon 2022-01-17 21:35:19 +08:00
parent d2bd8b44e0
commit 6dce7ead45
2 changed files with 40 additions and 3 deletions

View File

@ -1799,6 +1799,33 @@ TEST(parser, print_ddd) {
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(parser, __get__3) {
pikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)
"a = b[c+d] + e[f*j]\n";
printf("%s", lines);
char* pikaAsm = Parser_multiLineToAsm(buffs, (char*)lines);
printf("%s", pikaAsm);
EXPECT_STREQ(pikaAsm,
"B0\n"
"2 REF b\n"
"3 REF c\n"
"3 REF d\n"
"2 OPT +\n"
"1 RUN __get__\n"
"2 REF e\n"
"3 REF f\n"
"3 REF j\n"
"2 OPT *\n"
"1 RUN __get__\n"
"0 OPT +\n"
"0 OUT a\n"
);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(parser, __get__) {
pikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
@ -1838,4 +1865,4 @@ TEST(parser, __get__2) {
);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
}

View File

@ -631,18 +631,28 @@ char* Parser_solveRightBranckets(Args* outBuffs, char* right) {
} else if ((TOKEN_devider == token_type2) &&
(strEqu(pyload2, "]"))) {
is_in_brancket = 0;
char* index = args_getStr(buffs, "index");
Arg* index_arg = arg_setStr(NULL, "", index);
index_arg = arg_strAppend(index_arg, pyload1);
args_setStr(buffs, "index", arg_getStr(index_arg));
arg_deinit(index_arg);
right_arg = arg_strAppend(right_arg, "__get__(");
right_arg = arg_strAppend(right_arg, args_getStr(buffs, "obj"));
right_arg = arg_strAppend(right_arg, ",");
right_arg =
arg_strAppend(right_arg, args_getStr(buffs, "index"));
right_arg = arg_strAppend(right_arg, ")");
} else if (is_in_brancket) {
args_setStr(buffs, "index", "");
} else if (is_in_brancket && (!strEqu(pyload1, "["))) {
char* index = args_getStr(buffs, "index");
Arg* index_arg = arg_setStr(NULL, "", index);
index_arg = arg_strAppend(index_arg, pyload2);
index_arg = arg_strAppend(index_arg, pyload1);
args_setStr(buffs, "index", arg_getStr(index_arg));
arg_deinit(index_arg);
} else if (!is_in_brancket && (!strEqu(pyload1, "]"))) {
right_arg = arg_strAppend(right_arg, pyload1);
}
args_deinit(token_buffs);
}