diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2014-11-14 17:41:03 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2014-11-14 17:41:03 +0100 |
commit | 165cf9a5c6ab03dab64d5eb5a5577f8c216bb832 (patch) | |
tree | 8ab8fd9baa491d92d9f21f2e9257450adab4f75f /src/core/utils/Tokenizer.hpp | |
parent | e3cf0a9d726c9d76f4938590691336fbf2e9f6d5 (diff) |
implemented tokenizer test and started implementing CodeTokenizer under supervision of Maester Stoeckel.
Diffstat (limited to 'src/core/utils/Tokenizer.hpp')
-rw-r--r-- | src/core/utils/Tokenizer.hpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/core/utils/Tokenizer.hpp b/src/core/utils/Tokenizer.hpp index 924b670..eb8eed4 100644 --- a/src/core/utils/Tokenizer.hpp +++ b/src/core/utils/Tokenizer.hpp @@ -45,6 +45,9 @@ public: TokenTreeNode(const std::map<std::string, int> &inputs); }; +static const int TOKEN_NONE = -1; +static const int TOKEN_TEXT = -2; + struct Token { int tokenId; std::string content; @@ -63,10 +66,9 @@ struct Token { endLine(endLine) { } -}; -static const int TOKEN_NONE = -1; -static const int TOKEN_TEXT = -2; + Token() : tokenId(TOKEN_NONE) {} +}; class Tokenizer { private: @@ -77,6 +79,21 @@ private: bool prepare(); +protected: + /** + * This method is an interface to build multiple tokens from a single one in + * derived classes. This might be interesting if you want to implement + * further logic on text tokens or similar applications. + * + * @param t a Token the "basic" tokenizer found. + * @param peeked a reference to the deque containing all temporary Tokens. + * You are supposed to append your tokens there. In the trivial case you just + * put the given Token on top of the deque. + * @return false if no token was appended to the deque (meaning that you want + * to ignore the given token explicitly) and true in all other cases. + */ + virtual bool doPrepare(const Token &t, std::deque<Token> &peeked); + public: Tokenizer(BufferedCharReader &input, const TokenTreeNode &root); |