This commit is contained in:
bronku 2025-11-25 17:33:56 +01:00
parent 2be4542c1b
commit ced10cf298
5 changed files with 14 additions and 7 deletions

View file

@ -13,7 +13,8 @@
^[ \t]*\r?\n { /* Ignore lines containing whitespace only */ }
^[ \t]*#.*\n { /* Ignore comment-only lines */ }
^[ \t]+ {
^[ \t]* {
int col = indent_stack.calculateColumn(yytext, yyleng);
auto action = indent_stack.updateIndentation(col);
@ -21,6 +22,13 @@
if (action == IndentAction::Dedent) return yy::parser::token::TOK_DEDENT;
}
^. {
// Line starts with non-whitespace (column 0)
auto action = indent_stack.updateIndentation(0);
yyless(0);
if (action == IndentAction::Dedent) return yy::parser::token::TOK_DEDENT;
}
\n { return yy::parser::token::TOK_NEWLINE; }
def { return yy::parser::token::TOK_KW_DEF; }

View file

@ -4,5 +4,5 @@ def calculate(a, b=10):
print("Large result:", result)
return result
# This is a comment
# this is a comment
x = calculate(5, 15)

View file

@ -39,7 +39,6 @@ KW_RETURN
IDENTIFIER result
NEWLINE
DEDENT
NEWLINE
IDENTIFIER x
ASSIGN
IDENTIFIER calculate