[Saga-devel] saga SVN commit 3293: /trunk/saga/impl/packages/sd/

paul.livesey at stfc.ac.uk paul.livesey at stfc.ac.uk
Thu Jan 15 06:46:39 CST 2009


User: svn_plivesey
Date: 2009/01/15 06:46 AM

Added:
 /trunk/saga/impl/packages/sd/
  sd_parser_ext.hpp

Log:
 New class, derived from sd_parser does nothing but
 override reportError() so that we can do some custom
 error handling.

File Changes:

Directory: /trunk/saga/impl/packages/sd/
========================================

File [added]: sd_parser_ext.hpp
Delta lines: +97 -0
===================================================================
--- trunk/saga/impl/packages/sd/sd_parser_ext.hpp	2009-01-15 12:43:27 UTC (rev 3292)
+++ trunk/saga/impl/packages/sd/sd_parser_ext.hpp	2009-01-15 12:46:32 UTC (rev 3293)
@@ -0,0 +1,97 @@
+#ifndef SD_PARSER_EXT_HPP
+#define SD_PARSER_EXT_HPP
+
+#include "sd_parser.hpp"
+#include <string>
+#include <sstream>
+#include "saga/exception.hpp"
+class sd_parser_ext : public sd_parser
+{
+   public:
+
+   sd_parser_ext(antlr::TokenStream& lexer) : sd_parser(lexer)
+   {
+      setErrorFlag(false);
+      setErrorString("");
+   }
+
+   //Get the error flag
+   bool getErrorFlag() const
+   {
+      return _errorFlag;
+   }
+
+   //Set the error flag
+   void setErrorFlag(bool errorFlag)
+   {
+      _errorFlag = errorFlag;
+   }
+
+   //Get the error string
+   std::string getErrorString() const
+   {
+      return _errorString;
+   }
+
+   //Set the error string
+   void setErrorString(const std::string& errorString)
+   {
+      _errorString = errorString;
+   }
+
+   // Override the reportError function defined in the Parser base
+   // class.
+   void reportError(const std::string& s)
+   {
+      if ( getErrorFlag() == false )
+      {
+         setErrorFlag(true);
+
+         std::ostringstream os;
+ 
+         if ( getFilename()=="" )
+         {
+            os << "Error: " << s << std::endl;
+         }
+
+         else
+         {
+            os << "Error in " << getFilename()
+               << ": " << s << std::endl;
+         }
+         setErrorString(os.str());
+      }
+   }
+
+   // Override the reportError function defined in the Parser base
+   // class.
+   void reportError(const antlr::RecognitionException& ex)
+   {
+      if ( getErrorFlag() == false )
+      {
+         setErrorFlag(true);
+
+         std::ostringstream os;
+ 
+         if ( getFilename()=="" )
+         {
+            os << "Error: " << ex.toString() << std::endl;
+         }
+
+         else
+         {
+            os << "Error in " << getFilename()
+               << ": " << ex.toString() << std::endl;
+         }
+         setErrorString(os.str());
+      }
+   }
+
+   private:
+
+   bool _errorFlag;
+   std::string _errorString;
+};
+
+#endif
+



More information about the saga-devel mailing list