ParserBase.h

Go to the documentation of this file.
00001 #ifndef PARSER_BASE_H
00002 #define PARSER_BASE_H
00003 
00008 /*
00009  * Copyright (C) 2003,2004,2005  Enrico Zini <enrico@debian.org>
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Lesser General Public
00013  * License as published by the Free Software Foundation; either
00014  * version 2.1 of the License, or (at your option) any later version.
00015  *
00016  * This library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this library; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
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 // vim:set ts=4 sw=4:
00108 #endif

Generated on Sat Jan 17 03:28:50 2009 for libtagcoll by  doxygen 1.5.1