From 18996e0fc5b9817c73636f8521ce9a7bfb2851bc Mon Sep 17 00:00:00 2001 From: lyon1998 Date: Tue, 15 Feb 2022 15:30:05 +0800 Subject: [PATCH] combine 'break, continue' --- src/PikaParser.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/PikaParser.c b/src/PikaParser.c index 379930a7c..15aed9401 100644 --- a/src/PikaParser.c +++ b/src/PikaParser.c @@ -911,6 +911,21 @@ AST* AST_parseLine(char* line, Stack* block_stack) { } } + /* contral keyward */ + const char control_keywords[][9] = {"break", "continue"}; + for (int i = 0; i < sizeof(control_keywords) / 8; i++) { + char* keyward = control_keywords[i]; + uint8_t keyward_size = strGetSize(keyward); + if (strIsStartWith(line_start, keyward)) { + if ((line_start[keyward_size] == ' ') || + (line_start[keyward_size] == 0)) { + obj_setStr(ast, keyward, ""); + stmt = ""; + goto block_matched; + } + } + } + if (strIsStartWith(line_start, "for ")) { Args* list_buffs = New_strBuff(); char* line_buff = strsCopy(list_buffs, line_start + 4); @@ -944,20 +959,6 @@ AST* AST_parseLine(char* line, Stack* block_stack) { } goto block_matched; } - if (strIsStartWith(line_start, "break")) { - if ((line_start[5] == ' ') || (line_start[5] == 0)) { - obj_setStr(ast, "break", ""); - stmt = ""; - goto block_matched; - } - } - if (strIsStartWith(line_start, "continue")) { - if ((line_start[8] == ' ') || (line_start[8] == 0)) { - obj_setStr(ast, "continue", ""); - stmt = ""; - goto block_matched; - } - } if (strEqu(line_start, "return")) { obj_setStr(ast, "return", ""); stmt = "";