Skip to content

Commit

Permalink
Fix a bug with indentation of blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
akshanshbhatt committed Sep 3, 2022
1 parent 297d9e8 commit b74581e
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/lpython/parser/tokenizer.re
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,25 @@ int Tokenizer::lex(Allocator &al, YYSTYPE &yylval, Location &loc, diag::Diagnost
}
if (indent) {
indent = false;
if (last_indent_length == 0) {
last_indent_type = tok[0];
}
if (last_indent_type == tok[0]) {
indent_length.push_back(cur-tok);
last_indent_length = cur-tok;
RET(TK_INDENT);
if (cur[0] != ' ' && cur[0] != '\t'
&& last_indent_length < cur-tok) {
if (last_indent_length == 0) {
last_indent_type = tok[0];
}
if (last_indent_type == tok[0]) {
indent_length.push_back(cur-tok);
last_indent_length = cur-tok;
RET(TK_INDENT);
} else {
token_loc(loc);
throw parser_local::TokenizerError(
"Indentation should be of the same type "
"(either tabs or spaces)", {loc});
}
} else {
loc.first++; loc.last++;
token_loc(loc);
throw parser_local::TokenizerError(
"Indentation should be of the same type "
"(either tabs or spaces)", {loc});
"Expected an indented block.", {loc});
}
} else {
if(last_token == yytokentype::TK_NEWLINE
Expand All @@ -347,7 +354,7 @@ int Tokenizer::lex(Allocator &al, YYSTYPE &yylval, Location &loc, diag::Diagnost
RET(TK_DEDENT);
}
} else {
loc.first++; loc.last++;
token_loc(loc);
throw parser_local::TokenizerError(
"Indentation should be of the same type "
"(either tabs or spaces)", {loc});
Expand Down

0 comments on commit b74581e

Please sign in to comment.