Skip to content

Commit b74581e

Browse files
committed
Fix a bug with indentation of blocks.
1 parent 297d9e8 commit b74581e

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

src/lpython/parser/tokenizer.re

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,25 @@ int Tokenizer::lex(Allocator &al, YYSTYPE &yylval, Location &loc, diag::Diagnost
321321
}
322322
if (indent) {
323323
indent = false;
324-
if (last_indent_length == 0) {
325-
last_indent_type = tok[0];
326-
}
327-
if (last_indent_type == tok[0]) {
328-
indent_length.push_back(cur-tok);
329-
last_indent_length = cur-tok;
330-
RET(TK_INDENT);
324+
if (cur[0] != ' ' && cur[0] != '\t'
325+
&& last_indent_length < cur-tok) {
326+
if (last_indent_length == 0) {
327+
last_indent_type = tok[0];
328+
}
329+
if (last_indent_type == tok[0]) {
330+
indent_length.push_back(cur-tok);
331+
last_indent_length = cur-tok;
332+
RET(TK_INDENT);
333+
} else {
334+
token_loc(loc);
335+
throw parser_local::TokenizerError(
336+
"Indentation should be of the same type "
337+
"(either tabs or spaces)", {loc});
338+
}
331339
} else {
332-
loc.first++; loc.last++;
340+
token_loc(loc);
333341
throw parser_local::TokenizerError(
334-
"Indentation should be of the same type "
335-
"(either tabs or spaces)", {loc});
342+
"Expected an indented block.", {loc});
336343
}
337344
} else {
338345
if(last_token == yytokentype::TK_NEWLINE
@@ -347,7 +354,7 @@ int Tokenizer::lex(Allocator &al, YYSTYPE &yylval, Location &loc, diag::Diagnost
347354
RET(TK_DEDENT);
348355
}
349356
} else {
350-
loc.first++; loc.last++;
357+
token_loc(loc);
351358
throw parser_local::TokenizerError(
352359
"Indentation should be of the same type "
353360
"(either tabs or spaces)", {loc});

0 commit comments

Comments
 (0)