From 269b932a3bf720cfe259266726408411b3889b98 Mon Sep 17 00:00:00 2001 From: bronku Date: Tue, 25 Nov 2025 18:02:30 +0100 Subject: [PATCH] i hate this --- src/lexer.l | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lexer.l b/src/lexer.l index bdc00f0..3e6e9c7 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -1,7 +1,7 @@ %option c++ %option noyywrap %option yyclass="Scanner" -%x STRING_DQ STRING_SQ STRING_TDQ STRING_TSQ +%x STRING_DQ STRING_SQ STRING_TDQ STRING_TSQ NEWLINE %{ #include "scanner.hpp" @@ -10,11 +10,15 @@ %} %% + +^[ \t]*\r?\n { /* Ignore lines containing whitespace only */ } +^[ \t]*#.*\n { /* Ignore comment-only lines */ } ^[ \t]*\r?\n { /* Ignore lines containing whitespace only */ } ^[ \t]*#.*\n { /* Ignore comment-only lines */ } -^[ \t]+ { +[ \t]+ { + BEGIN(INITIAL); int col = indent_stack.calculateColumn(yytext, yyleng); auto action = indent_stack.updateIndentation(col); @@ -22,14 +26,16 @@ if (action == IndentAction::Dedent) return yy::parser::token::TOK_DEDENT; } -^. { +. { + BEGIN(INITIAL); // Line starts with non-whitespace (column 0) auto action = indent_stack.updateIndentation(0); yyless(0); + if (action == IndentAction::Indent) return yy::parser::token::TOK_INDENT; if (action == IndentAction::Dedent) return yy::parser::token::TOK_DEDENT; } -\n { return yy::parser::token::TOK_NEWLINE; } +\n { BEGIN(NEWLINE);return yy::parser::token::TOK_NEWLINE; } def { return yy::parser::token::TOK_KW_DEF; } if { return yy::parser::token::TOK_KW_IF; }