i hate this
This commit is contained in:
parent
619ea2c03f
commit
269b932a3b
1 changed files with 10 additions and 4 deletions
14
src/lexer.l
14
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 @@
|
|||
%}
|
||||
|
||||
%%
|
||||
|
||||
<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]*#.*\n { /* Ignore comment-only lines */ }
|
||||
|
||||
|
||||
^[ \t]+ {
|
||||
<NEWLINE>[ \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;
|
||||
}
|
||||
|
||||
^. {
|
||||
<NEWLINE>. {
|
||||
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; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue