From 356cdaf05129e4ffd7dd71d098633d2b42b9ce5e Mon Sep 17 00:00:00 2001 From: Riyyi Date: Thu, 30 Jun 2022 20:23:44 +0200 Subject: [PATCH] Util: Add increment() and decrement() to Lexer --- src/util/json/lexer.cpp | 30 ++++++++++++++++++------------ src/util/json/lexer.h | 2 ++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/util/json/lexer.cpp b/src/util/json/lexer.cpp index b3cd41b..2024236 100644 --- a/src/util/json/lexer.cpp +++ b/src/util/json/lexer.cpp @@ -130,8 +130,7 @@ void Lexer::analyze() break; } - m_index++; - m_column++; + increment(); } } @@ -147,11 +146,22 @@ char Lexer::peekNext() return m_job->input()[m_index + 1]; } -char Lexer::consume() +void Lexer::increment() { - char character = peek(); m_index++; m_column++; +} + +void Lexer::decrement() +{ + m_index--; + m_column--; +} + +char Lexer::consume() +{ + char character = peek(); + increment(); return character; } @@ -161,8 +171,7 @@ bool Lexer::consumeSpecific(char character) return false; } - m_index++; - m_column++; + increment(); return true; } @@ -196,9 +205,8 @@ bool Lexer::getString() break; } - m_index++; - m_column++; symbol += character; + increment(); } printf("Pushing -> String: \"%s\"\t%zu[%zu]\n", symbol.c_str(), m_line, column); @@ -221,12 +229,10 @@ bool Lexer::getNumberOrLiteral(Token::Type type) break; } - m_index++; - m_column++; symbol += character; + increment(); } - m_index--; - m_column--; + decrement(); m_tokens->push_back({ type, m_line, column, symbol }); diff --git a/src/util/json/lexer.h b/src/util/json/lexer.h index c468114..e6a46c2 100644 --- a/src/util/json/lexer.h +++ b/src/util/json/lexer.h @@ -51,6 +51,8 @@ private: char peek(); char peekNext(); + void increment(); + void decrement(); char consume(); bool consumeSpecific(char character);