]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/Tokenizer.h
added comments (/*…*/ and //…\n)
[l2e.git] / src / loader / Tokenizer.h
index b7ca72f664c148c1f92029a27cc132fbdb7682ce..dff96fc6167495769ba82d5a56bd57d6dc9f497a 100644 (file)
@@ -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;
 
 };