From: Daniel Karbach Date: Sun, 26 Aug 2012 14:47:44 +0000 (+0200) Subject: introduced exception type for tokenizer X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=2aba2da49a94fac57c7d2a469455102cf194957d;p=l2e.git introduced exception type for tokenizer --- diff --git a/src/loader/Tokenizer.cpp b/src/loader/Tokenizer.cpp index 76a3a14..2b87d9c 100644 --- a/src/loader/Tokenizer.cpp +++ b/src/loader/Tokenizer.cpp @@ -8,7 +8,6 @@ #include "Tokenizer.h" #include -#include namespace loader { @@ -18,7 +17,7 @@ bool Tokenizer::HasMore() { void Tokenizer::Putback(const Token &t) { if (isPutback) { - throw std::runtime_error("Tokenizer: double putback not supported"); + throw LexerError("Tokenizer: double putback not supported"); } else { putback = t; isPutback = true; @@ -65,7 +64,7 @@ Tokenizer::Token Tokenizer::ReadToken() { } else if (std::islower(c)) { CheckKeyword(t); } else { - throw std::runtime_error(std::string("Tokenizer: cannot parse token: ") + c); + throw LexerError(std::string("Tokenizer: cannot parse token: ") + c); } return t; } @@ -105,7 +104,7 @@ Tokenizer::Token Tokenizer::ReadString() { std::istream::char_type c; in.get(c); if (c != '"') { - throw std::runtime_error("Tokenizer: strings must begin with '\"'"); + throw LexerError("Tokenizer: strings must begin with '\"'"); } while (in.get(c)) { diff --git a/src/loader/Tokenizer.h b/src/loader/Tokenizer.h index 15eadf8..f2ab4aa 100644 --- a/src/loader/Tokenizer.h +++ b/src/loader/Tokenizer.h @@ -10,6 +10,7 @@ #include #include +#include #include namespace loader { @@ -55,6 +56,11 @@ public: }; + class LexerError: public std::runtime_error { + public: + explicit LexerError(const std::string &msg) : std::runtime_error(msg) { } + }; + bool HasMore(); Token GetNext(); void Putback(const Token &);