X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FTokenizer.h;h=dff96fc6167495769ba82d5a56bd57d6dc9f497a;hb=51e0a94d0e0a3bc1a4664aa9af1f20910f55201c;hp=b7ca72f664c148c1f92029a27cc132fbdb7682ce;hpb=00dafa489224450ccc0321e238c176b9e8aa34bc;p=l2e.git diff --git a/src/loader/Tokenizer.h b/src/loader/Tokenizer.h index b7ca72f..dff96fc 100644 --- a/src/loader/Tokenizer.h +++ b/src/loader/Tokenizer.h @@ -18,7 +18,8 @@ namespace loader { class Tokenizer { public: - explicit Tokenizer(std::istream &in) : in(in), isPutback(false) { } + explicit Tokenizer(std::istream &in) + : in(in), line(1), isPutback(false), skipComments(true) { } ~Tokenizer() { } private: Tokenizer(const Tokenizer &); @@ -47,6 +48,7 @@ public: KEYWORD_TRUE = 't', IDENTIFIER = 'x', TYPE_NAME = 'n', + COMMENT = 'c' }; Token() : type(UNKNOWN), number(0) { } @@ -60,27 +62,38 @@ public: class LexerError: public std::runtime_error { public: - explicit LexerError(const std::string &msg) : std::runtime_error(msg) { } + LexerError(int line, const std::string &msg) + : std::runtime_error(msg), line(line) { } + int Line() const { return line; } + private: + int line; }; bool HasMore(); Token GetNext(); const Token &Peek(); void Putback(const Token &); + int Line() const { return line; } private: + void ScanSpace(); Token ReadToken(); Token ReadNumber(); Token ReadString(); Token ReadIdentifier(); + Token ReadComment(); + Token ReadMultilineComment(); + bool CheckKeyword(Token &); private: std::istream ∈ Token putback; + int line; bool isPutback; + bool skipComments; };