allow 'elif' for Python compatibility

This commit is contained in:
K. Lange 2021-01-04 09:13:39 +09:00
parent 3415fd4e73
commit 132542c6ab
4 changed files with 8 additions and 4 deletions

View File

@ -1015,8 +1015,8 @@ static void ifStatement() {
previous = parser.previous;
advance();
}
if (match(TOKEN_ELSE)) {
if (check(TOKEN_IF)) {
if (match(TOKEN_ELSE) || check(TOKEN_ELIF)) {
if (parser.current.type == TOKEN_ELIF || check(TOKEN_IF)) {
parser.previous = myPrevious;
ifStatement(); /* Keep nesting */
} else {

View File

@ -521,7 +521,7 @@ void paint_krk_string(struct syntax_state * state, int type) {
char * syn_krk_keywords[] = {
"and","class","def","else","export","for","if","in","import",
"let","not","or","print","return","while","try","except","raise",
"continue","break","as","from",
"continue","break","as","from","elif",
NULL
};

View File

@ -202,7 +202,10 @@ static KrkTokenType identifierType() {
} break;
case 'd': return checkKeyword(1, "ef", TOKEN_DEF);
case 'e': if (MORE(1)) switch(scanner.start[1]) {
case 'l': return checkKeyword(2, "se", TOKEN_ELSE);
case 'l': if (MORE(2)) switch(scanner.start[2]) {
case 's': return checkKeyword(3,"e", TOKEN_ELSE);
case 'i': return checkKeyword(3,"f", TOKEN_ELIF);
} break;
case 'x': if MORE(2) switch(scanner.start[2]) {
case 'p': return checkKeyword(3, "ort", TOKEN_EXPORT);
case 'c': return checkKeyword(3, "ept", TOKEN_EXCEPT);

View File

@ -66,6 +66,7 @@ typedef enum {
TOKEN_AS,
TOKEN_FROM,
TOKEN_ELIF, /* Provided for compatibility, recommend `else if` instead. */
TOKEN_ERROR,
TOKEN_EOF,