diff --git a/src/indent_helper.hpp b/src/indent_helper.hpp index 9e27916..fcc8ad0 100644 --- a/src/indent_helper.hpp +++ b/src/indent_helper.hpp @@ -1,5 +1,11 @@ #pragma once #include +enum class IndentAction +{ + Indent, + Dedent, + None +}; class IndentHelper { @@ -9,19 +15,19 @@ class IndentHelper public: IndentHelper() { indent_stack.push(0); } - int processLine(int spaces) + IndentAction processLine(int spaces) { int current = indent_stack.top(); if (spaces == current) { - return 0; + return IndentAction::None; } if (spaces > current) { indent_stack.push(spaces); - return 1; + return IndentAction::Indent; } pending_dedents = 0; @@ -34,10 +40,10 @@ public: if (pending_dedents > 0) { pending_dedents--; - return -1; + return IndentAction::Dedent; } - return 0; + return IndentAction::None; } // returns false on failure diff --git a/src/lexer.l b/src/lexer.l index 9658e35..3ec588b 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -18,9 +18,9 @@ for (int i = 0; i < yyleng; i++) spaces += (yytext[i] == '\t') ? 8 : 1; - int result = indent_helper.processLine(spaces); - if (result > 0) return yy::parser::token::TOK_INDENT; - if (result < 0) return yy::parser::token::TOK_DEDENT; + 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; } \n { return yy::parser::token::TOK_NEWLINE; } diff --git a/src/scanner.hpp b/src/scanner.hpp index f78194e..f86630d 100644 --- a/src/scanner.hpp +++ b/src/scanner.hpp @@ -25,9 +25,7 @@ public: if (token == yy::parser::token::TOK_EOF) { - int result = indent_helper.processLine(0); - - if (result == -1) + if (indent_helper.processLine(0) == IndentAction::Dedent) { return yy::parser::token::TOK_DEDENT; }