From: Daniel Karbach Date: Sun, 26 Aug 2012 15:16:51 +0000 (+0200) Subject: added peek function to tokenizer X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=00dafa489224450ccc0321e238c176b9e8aa34bc;p=l2e.git added peek function to tokenizer --- diff --git a/src/loader/Tokenizer.cpp b/src/loader/Tokenizer.cpp index 828f6ed..c5cc561 100644 --- a/src/loader/Tokenizer.cpp +++ b/src/loader/Tokenizer.cpp @@ -24,6 +24,14 @@ void Tokenizer::Putback(const Token &t) { } } +const Tokenizer::Token &Tokenizer::Peek() { + if (!isPutback) { + putback = GetNext(); + isPutback = true; + } + return putback; +} + Tokenizer::Token Tokenizer::GetNext() { if (isPutback) { isPutback = false; diff --git a/src/loader/Tokenizer.h b/src/loader/Tokenizer.h index 80a3169..b7ca72f 100644 --- a/src/loader/Tokenizer.h +++ b/src/loader/Tokenizer.h @@ -28,7 +28,7 @@ public: struct Token { enum Type { - UNKNOWN, + UNKNOWN = 0, ANGLE_BRACKET_OPEN = '{', ANGLE_BRACKET_CLOSE = '}', CHEVRON_OPEN = '<', @@ -39,14 +39,14 @@ public: BRACKET_CLOSE = ']', PARENTHESIS_OPEN = '(', PARENTHESIS_CLOSE = ')', - NUMBER, - STRING, - KEYWORD_EXPORT, - KEYWORD_FALSE, - KEYWORD_INCLUDE, - KEYWORD_TRUE, - IDENTIFIER, - TYPE_NAME, + NUMBER = '0', + STRING = '"', + KEYWORD_EXPORT = 'e', + KEYWORD_FALSE = 'f', + KEYWORD_INCLUDE = 'i', + KEYWORD_TRUE = 't', + IDENTIFIER = 'x', + TYPE_NAME = 'n', }; Token() : type(UNKNOWN), number(0) { } @@ -65,6 +65,7 @@ public: bool HasMore(); Token GetNext(); + const Token &Peek(); void Putback(const Token &); private: