i hate this

This commit is contained in:
bronku 2025-11-25 18:02:30 +01:00
parent 619ea2c03f
commit 269b932a3b

View file

@ -1,7 +1,7 @@
%option c++ %option c++
%option noyywrap %option noyywrap
%option yyclass="Scanner" %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" #include "scanner.hpp"
@ -10,11 +10,15 @@
%} %}
%% %%
<NEWLINE>^[ \t]*\r?\n { /* Ignore lines containing whitespace only */ }
<NEWLINE>^[ \t]*#.*\n { /* Ignore comment-only lines */ }
^[ \t]*\r?\n { /* Ignore lines containing whitespace only */ } ^[ \t]*\r?\n { /* Ignore lines containing whitespace only */ }
^[ \t]*#.*\n { /* Ignore comment-only lines */ } ^[ \t]*#.*\n { /* Ignore comment-only lines */ }
^[ \t]+ { <NEWLINE>[ \t]+ {
BEGIN(INITIAL);
int col = indent_stack.calculateColumn(yytext, yyleng); int col = indent_stack.calculateColumn(yytext, yyleng);
auto action = indent_stack.updateIndentation(col); auto action = indent_stack.updateIndentation(col);
@ -22,14 +26,16 @@
if (action == IndentAction::Dedent) return yy::parser::token::TOK_DEDENT; if (action == IndentAction::Dedent) return yy::parser::token::TOK_DEDENT;
} }
^. { <NEWLINE>. {
BEGIN(INITIAL);
// Line starts with non-whitespace (column 0) // Line starts with non-whitespace (column 0)
auto action = indent_stack.updateIndentation(0); auto action = indent_stack.updateIndentation(0);
yyless(0); yyless(0);
if (action == IndentAction::Indent) return yy::parser::token::TOK_INDENT;
if (action == IndentAction::Dedent) return yy::parser::token::TOK_DEDENT; 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; } def { return yy::parser::token::TOK_KW_DEF; }
if { return yy::parser::token::TOK_KW_IF; } if { return yy::parser::token::TOK_KW_IF; }