Skip to content

Commit

Permalink
Recognise the last indent type and check it with the current indent t…
Browse files Browse the repository at this point in the history
…ype.

Co-authored-by: Thirumalai Shaktivel <Thirumalai-Shaktivel@users.noreply.github.com>
  • Loading branch information
akshanshbhatt and Thirumalai-Shaktivel committed Aug 31, 2022
1 parent a227df8 commit e049dcf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/lpython/parser/tokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Tokenizer
int dedent = 0; // Allowed values: 0, 1, 2, see the code below the meaning of this state variable
bool colon_actual_last_token = false; // If the actual last token was a colon
long int last_indent_length = 0;
unsigned char last_indent_type;
std::vector<uint64_t> indent_length;

char paren_stack[MAX_PAREN_LEVEL];
Expand Down
16 changes: 13 additions & 3 deletions src/lpython/parser/tokenizer.re
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,19 @@ int Tokenizer::lex(Allocator &al, YYSTYPE &yylval, Location &loc, diag::Diagnost
}
if (indent) {
indent = false;
indent_length.push_back(cur-tok);
last_indent_length = cur-tok;
RET(TK_INDENT);
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 {
loc.first++; loc.last++;
throw parser_local::TokenizerError(
"Indentation should be of the same type "
"(either tabs or spaces)", {loc});
}
} else {
if(last_token == yytokentype::TK_NEWLINE && cur[0] != ' '
&& cur[0] != '\t' && last_indent_length > cur-tok) {
Expand Down

0 comments on commit e049dcf

Please sign in to comment.