extracted line couting
This commit is contained in:
parent
7f24975092
commit
60eaba951a
2 changed files with 17 additions and 6 deletions
11
src/lexer.l
11
src/lexer.l
|
|
@ -14,15 +14,14 @@
|
|||
^[ \t]*#.*\n { /* Ignore comment-only lines */ }
|
||||
|
||||
^[ \t]* {
|
||||
int spaces = 0;
|
||||
for (int i = 0; i < yyleng; i++)
|
||||
spaces += (yytext[i] == '\t') ? 8 : 1;
|
||||
int col = indent_helper.calculateColumn(yytext, yyleng);
|
||||
auto action = indent_helper.processLine(col);
|
||||
|
||||
IndentAction result = indent_helper.processLine(spaces);
|
||||
if (result == IndentAction::Indent) return yy::parser::token::TOK_INDENT;
|
||||
if (result == IndentAction::Dedent) return yy::parser::token::TOK_DEDENT;
|
||||
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; }
|
||||
|
||||
def { return yy::parser::token::TOK_KW_DEF; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue