Skip to content

Commit 99ea824

Browse files
authored
Merge pull request #381 from akkako/fix/shell-block-else
fix(shell): keep else/elif/except/finally inside multi-line REPL block
2 parents cad769e + ebf2a53 commit 99ea824

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

src/PikaObj.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,29 @@ static void handle_history_navigation(char inputChar,
18071807
return;
18081808
}
18091809

1810+
static pika_bool _shell_lineStaysInBlock(char* line) {
1811+
if ((line[0] == ' ') || (line[0] == '\t')) {
1812+
return pika_true;
1813+
}
1814+
if (strIsStartWith(line, "else") &&
1815+
((line[4] == ' ') || (line[4] == ':'))) {
1816+
return pika_true;
1817+
}
1818+
if (strIsStartWith(line, "elif") &&
1819+
((line[4] == ' ') || (line[4] == ':'))) {
1820+
return pika_true;
1821+
}
1822+
if (strIsStartWith(line, "except") &&
1823+
((line[6] == ' ') || (line[6] == ':'))) {
1824+
return pika_true;
1825+
}
1826+
if (strIsStartWith(line, "finally") &&
1827+
((line[7] == ' ') || (line[7] == ':'))) {
1828+
return pika_true;
1829+
}
1830+
return pika_false;
1831+
}
1832+
18101833
enum shellCTRL _inner_do_obj_runChar(PikaObj* self,
18111834
char inputChar,
18121835
ShellConfig* shell) {
@@ -1995,7 +2018,7 @@ enum shellCTRL _inner_do_obj_runChar(PikaObj* self,
19952018
obj_setStr(self, shell->blockBuffName, shell_buff_new);
19962019
strsDeinit(&buffs);
19972020
/* go out from block */
1998-
if ((shell->lineBuff[0] != ' ') && (shell->lineBuff[0] != '\t')) {
2021+
if (!_shell_lineStaysInBlock(shell->lineBuff)) {
19992022
shell->inBlock = pika_false;
20002023
input_line = obj_getStr(self, shell->blockBuffName);
20012024
ctrl = shell->handler(self, input_line, shell);

0 commit comments

Comments
 (0)