00001 #ifndef PARSER_BASE_H
00002 #define PARSER_BASE_H
00003
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <string>
00027 #include <tagcoll/Exception.h>
00028
00029 namespace Tagcoll {
00030
00031 class ParserInput;
00032
00036 class ParserException: public ContextException
00037 {
00038 protected:
00039 std::string _file;
00040 int _line;
00041
00042 public:
00043 ParserException(const ParserInput& input, const std::string& message) throw ();
00044 ParserException(const std::string& file, int line, const std::string& message) throw ()
00045 : ContextException(message), _file(file), _line(line) {}
00046 ParserException(int line, const std::string& message) throw ()
00047 : ContextException(message), _line(line) {}
00048 ParserException(const std::string& message) throw ()
00049 : ContextException(message), _line(-1) {}
00050 virtual ~ParserException() throw () {}
00051
00052 int line() const throw () { return _line; }
00053 int line(int line) throw () { return _line = line; }
00054
00055 const std::string& file() const throw () { return _file; }
00056 std::string file() throw () { return _file; }
00057 std::string file(const std::string file) throw () { return _file = file; }
00058
00059 virtual const char* type() const throw ()
00060 {
00061 return "ParserException";
00062 }
00063
00064 virtual std::string desc() const throw ();
00065 };
00066
00070 class ParserInputException : public ParserException
00071 {
00072 public:
00073 ParserInputException(const ParserInput& input, const std::string& message) throw ()
00074 : ParserException(input, message) {}
00075 virtual ~ParserInputException() throw () {}
00076
00077 virtual const char* type() const throw ()
00078 {
00079 return "ParserInputException";
00080 }
00081
00082 };
00083
00091 class ParserInput
00092 {
00093 public:
00094 static const int Eof = -1;
00095
00096 ParserInput() {}
00097 virtual ~ParserInput() {}
00098
00099 virtual const std::string& fileName() const = 0;
00100 virtual int lineNumber() const = 0;
00101 virtual int nextChar() throw (ParserInputException) = 0;
00102 virtual void pushChar(int c) throw (ParserInputException) = 0;
00103 };
00104
00105 }
00106
00107
00108 #endif