mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
support multiline connection
This commit is contained in:
parent
83b3611c4a
commit
e8ffa73d2a
@ -1,2 +1,2 @@
|
||||
#undef PIKA_STACK_BUFF_SIZE
|
||||
#define PIKA_STACK_BUFF_SIZE 1024
|
||||
#define PIKA_STACK_BUFF_SIZE 2048
|
@ -1,4 +1,4 @@
|
||||
#undef PIKA_OPTIMIZE
|
||||
#define PIKA_OPTIMIZE PIKA_OPTIMIZE_SPEED
|
||||
#undef PIKA_STACK_BUFF_SIZE
|
||||
#define PIKA_STACK_BUFF_SIZE 1024
|
||||
#define PIKA_STACK_BUFF_SIZE 2048
|
@ -1,4 +1,4 @@
|
||||
#undef PIKA_SYNTAX_LEVEL
|
||||
#define PIKA_SYNTAX_LEVEL PIKA_SYNTAX_LEVEL_MINIMAL
|
||||
#undef PIKA_STACK_BUFF_SIZE
|
||||
#define PIKA_STACK_BUFF_SIZE 1024
|
||||
#define PIKA_STACK_BUFF_SIZE 2048
|
@ -25,8 +25,61 @@ def test_start():
|
||||
# data1 = "{"data":{"jjj":"","333":"no","startupLogo":"4","cardType":"00,01,02,03,04","synfromhis":"no","alarmThresholdValue":"37.2","hospitalName":"jell","facediscernMode":"01","hospitalCode":"102"},"success":true,"resultCode":"0000","time":"2022-05-20 14:10:27","message":"ok"}"
|
||||
#data1 = "{\"data\":{\"requestSocialInsuranceFromYangCheng\":\"\",\"authenticationComparison\":\"no\",\"startupLogo\":\"4\",\"cardType\":\"00,01,02,03,04\",\"synfromhis\":\"no\",\"alarmThresholdValue\":\"37.2\",\"hospitalName\":\"余杭农贸市场\",\"facediscernMode\":\"01\",\"hospitalCode\":\"102\"},\"success\":true,\"resultCode\":\"0000\",\"time\":\"2022-05-20 14:10:27\",\"message\":\"操作成功\"} "
|
||||
#data1 = '{"sites": [{ "name":"Google", "info":[ "Android", "Google 搜索", "Google 翻译" ] }],"arraytest":{"test1":["c", "Java", "Python"],"test2":["c2", "Java2", "Python2"]},"data":{"requestSocialInsuranceFromYangCheng":"","authenticationComparison":"no","startupLogo":"4","cardType":"00,01,02,03,04","synfromhis":"no","alarmThresholdValue":"37.2","hospitalName":"余杭农贸市场","facediscernMode":"01","hospitalCode":"102"},"success":"true","resultCode":"0000","time":"2022-05-20 14:10:27","message":"操作成功"}'
|
||||
data1 = '{"sites": [{ "name":"Google", "info":[ "Android", "Google search", "Google translation" ] },{ "name":"Runoob", "info":[ "ciniao jiaoc", "ciniao tool", "ciniao wechat" ] },{ "name":"Taobao", "info":[ "taobao", "shopping" ] }],"arraytest":{"test1":["c", "Java", "Python"],"test2":["c2", "Java2", "Python2"]},"data":{"requestSocialInsuranceFromYangCheng":"","authenticationComparison":"no","startupLogo":"4","cardType":"00,01,02,03,04","synfromhis":"no","alarmThresholdValue":"37.2","hospitalName":"余杭农贸市场","facediscernMode":"01","hospitalCode":"102"},"success":"true","resultCode":"0000","time":"2022-05-20 14:10:27","message":"操作成功"}'
|
||||
|
||||
# data1 = '{"sites": [{ "name":"Google", "info":[ "Android", "Google search", "Google translation" ] },{ "name":"Runoob", "info":[ "ciniao jiaoc", "ciniao tool", "ciniao wechat" ] },{ "name":"Taobao", "info":[ "taobao", "shopping" ] }],"arraytest":{"test1":["c", "Java", "Python"],"test2":["c2", "Java2", "Python2"]},"data":{"requestSocialInsuranceFromYangCheng":"","authenticationComparison":"no","startupLogo":"4","cardType":"00,01,02,03,04","synfromhis":"no","alarmThresholdValue":"37.2","hospitalName":"余杭农贸市场","facediscernMode":"01","hospitalCode":"102"},"success":"true","resultCode":"0000","time":"2022-05-20 14:10:27","message":"操作成功"}'
|
||||
data1 = '{\
|
||||
"sites":[\
|
||||
{\
|
||||
"name":"Google",\
|
||||
"info":[\
|
||||
"Android",\
|
||||
"Google search",\
|
||||
"Google translation"\
|
||||
]\
|
||||
},\
|
||||
{\
|
||||
"name":"Runoob",\
|
||||
"info":[\
|
||||
"ciniao jiaoc",\
|
||||
"ciniao tool",\
|
||||
"ciniao wechat"\
|
||||
]\
|
||||
},\
|
||||
{\
|
||||
"name":"Taobao",\
|
||||
"info":[\
|
||||
"taobao",\
|
||||
"shopping"\
|
||||
]\
|
||||
}\
|
||||
],\
|
||||
"arraytest":{\
|
||||
"test1":[\
|
||||
"c",\
|
||||
"Java",\
|
||||
"Python"\
|
||||
],\
|
||||
"test2":[\
|
||||
"c2",\
|
||||
"Java2",\
|
||||
"Python2"\
|
||||
]\
|
||||
},\
|
||||
"data":{\
|
||||
"requestSocialInsuranceFromYangCheng":"",\
|
||||
"authenticationComparison":"no",\
|
||||
"startupLogo":"4",\
|
||||
"cardType":"00,01,02,03,04",\
|
||||
"synfromhis":"no",\
|
||||
"alarmThresholdValue":"37.2",\
|
||||
"hospitalName":"余杭农贸市场",\
|
||||
"facediscernMode":"01",\
|
||||
"hospitalCode":"102"\
|
||||
},\
|
||||
"success":"true",\
|
||||
"resultCode":"0000",\
|
||||
"time":"2022-05-20 14:10:27",\
|
||||
"message":"操作成功"\
|
||||
}'
|
||||
a = cjson.Parse(data1)
|
||||
a.print()
|
||||
success = a.getObjectItem("success")
|
||||
|
@ -3076,4 +3076,43 @@ TEST(parser, cjson_test4) {
|
||||
args_deinit(buffs);
|
||||
arg_deinit(lines_buff);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(parser, connection) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
Args* buffs = New_strBuff();
|
||||
char* lines =
|
||||
"print('\\\n"
|
||||
"test')\n";
|
||||
printf("%s", lines);
|
||||
char* pikaAsm = Parser_multiLineToAsm(buffs, lines);
|
||||
printf("%s", pikaAsm);
|
||||
EXPECT_STREQ(pikaAsm,
|
||||
"B0\n"
|
||||
"1 STR test\n"
|
||||
"0 RUN print\n");
|
||||
args_deinit(buffs);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(parser, connection2) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
Args* buffs = New_strBuff();
|
||||
char* lines =
|
||||
"a = \\\n"
|
||||
"3\n"
|
||||
"print\\\n"
|
||||
"(a)\n";
|
||||
printf("%s", lines);
|
||||
char* pikaAsm = Parser_multiLineToAsm(buffs, lines);
|
||||
printf("%s", pikaAsm);
|
||||
EXPECT_STREQ(pikaAsm,
|
||||
"B0\n"
|
||||
"0 NUM 3\n"
|
||||
"0 OUT a\n"
|
||||
"B0\n"
|
||||
"1 REF a\n"
|
||||
"0 RUN print\n");
|
||||
args_deinit(buffs);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
@ -1673,6 +1673,8 @@ char* Parser_parsePyLines(Args* outBuffs,
|
||||
uint16_t lines_num = strCountSign(py_lines, '\n');
|
||||
uint16_t lines_index = 0;
|
||||
uint8_t is_in_multi_comment = 0;
|
||||
Arg* line_connection_arg = arg_setStr(NULL, "", "");
|
||||
uint8_t is_line_connection = 0;
|
||||
char* out_ASM = NULL;
|
||||
char* single_ASM;
|
||||
uint32_t line_size = 0;
|
||||
@ -1684,10 +1686,30 @@ char* Parser_parsePyLines(Args* outBuffs,
|
||||
/* get single line by pop multiline */
|
||||
char* line_origin =
|
||||
strsGetFirstToken(&buffs, py_lines + lines_offset, '\n');
|
||||
char* line = line_origin;
|
||||
|
||||
char* line = strsCopy(&buffs, line_origin);
|
||||
/* line connection */
|
||||
if (is_line_connection) {
|
||||
is_line_connection = 0;
|
||||
line_connection_arg = arg_strAppend(line_connection_arg, line);
|
||||
line = strsCopy(&buffs, arg_getStr(line_connection_arg));
|
||||
/* reflash the line_connection_arg */
|
||||
arg_deinit(line_connection_arg);
|
||||
line_connection_arg = arg_setStr(NULL, "", "");
|
||||
}
|
||||
|
||||
/* check connection */
|
||||
if ('\\' == line[strGetSize(line) - 1]) {
|
||||
/* remove the '\\' */
|
||||
line[strGetSize(line) - 1] = '\0';
|
||||
is_line_connection = 1;
|
||||
line_connection_arg = arg_strAppend(line_connection_arg, line);
|
||||
goto next_line;
|
||||
}
|
||||
|
||||
/* support Tab */
|
||||
line = strsReplace(&buffs, line_origin, "\t", " ");
|
||||
line = strsReplace(&buffs, line, "\t", " ");
|
||||
|
||||
/* filter for not end \n */
|
||||
if (lines_index != lines_num) {
|
||||
if (Parser_isVoidLine(line)) {
|
||||
@ -1743,6 +1765,9 @@ exit:
|
||||
if (NULL != asm_buff) {
|
||||
arg_deinit(asm_buff);
|
||||
}
|
||||
if (NULL != line_connection_arg) {
|
||||
arg_deinit(line_connection_arg);
|
||||
}
|
||||
stack_deinit(&block_stack);
|
||||
return out_ASM;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user