support Tab

This commit is contained in:
lyon 2022-05-26 16:14:11 +08:00
parent 6b63c13bef
commit dad0a82b3a
3 changed files with 51 additions and 5 deletions

View File

@ -2641,3 +2641,43 @@ TEST(parser, hex_iteral) {
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(parser, tab) {
pikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines =
"for i in range(0, 100):\n"
"\tprint(i)\n"
"\n";
char* tokens_str = Lexer_printTokens(buffs, Lexer_getTokens(buffs, lines));
printf("%s\n", tokens_str);
printf("%s", lines);
char* pikaAsm = Parser_multiLineToAsm(buffs, lines);
printf("%s", pikaAsm);
EXPECT_STREQ(pikaAsm,
"B0\n"
"2 NUM 0\n"
"2 NUM 100\n"
"1 RUN range\n"
"0 RUN iter\n"
"0 OUT _l0\n"
"0 REF _r1\n"
"0 REF _r2\n"
"0 OUT _l0.a2\n"
"0 OUT _l0.a1\n"
"B0\n"
"0 RUN _l0.__next__\n"
"0 OUT i\n"
"0 EST i\n"
"0 JEZ 2\n"
"B1\n"
"1 REF i\n"
"0 RUN print\n"
"B0\n"
"0 JMP -1\n"
"B0\n"
"0 DEL _l0\n"
"B0\n");
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -713,7 +713,7 @@ void obj_shellLineProcess(PikaObj* self,
obj_setStr(self, "shell_buff", shell_buff_new);
strsDeinit(&buffs);
/* go out from block */
if (rxBuff[0] != ' ') {
if ((rxBuff[0] != ' ') && (rxBuff[0] != '\t')) {
is_in_block = 0;
input_line = obj_getStr(self, "shell_buff");
if (SHELL_STATE_EXIT ==

View File

@ -1435,7 +1435,7 @@ static char* Parser_PreProcess_from(Args* buffs_p, char* line) {
}
/* skip PikaObj */
if (strEqu(module, "PikaObj")){
if (strEqu(module, "PikaObj")) {
line_out = strsCopy(buffs_p, "");
goto exit;
}
@ -1466,7 +1466,7 @@ exit:
char* Parser_LineToAsm(Args* buffs_p, char* line, Stack* blockStack) {
char* ASM = NULL;
AST* ast = NULL;
uint8_t line_num = 0;
uint8_t line_num = 0;
/* pre process */
line = Parser_linePreProcess(buffs_p, line);
if (NULL == line) {
@ -1553,7 +1553,13 @@ char* Parser_parsePyLines(Args* outBuffs,
lines_index++;
Args buffs = {0};
/* get single line by pop multiline */
char* line = strsGetFirstToken(&buffs, py_lines + lines_offset, '\n');
char* line_origin =
strsGetFirstToken(&buffs, py_lines + lines_offset, '\n');
char* line = line_origin;
/* support Tab */
if (strIsContain(line_origin, '\t')) {
line = strsReplace(&buffs, line_origin, "\t", " ");
}
/* filter for not end \n */
if (lines_index != lines_num) {
if (Parser_isVoidLine(line)) {
@ -1587,7 +1593,7 @@ char* Parser_parsePyLines(Args* outBuffs,
byteCodeFrame_appendFromAsm(bytecode_frame, single_ASM);
}
next_line:
line_size = strGetSize(line);
line_size = strGetSize(line_origin);
lines_offset = lines_offset + line_size + 1;
strsDeinit(&buffs);
/* exit when finished */