Author: sytyi
Date: Sat Aug  6 23:32:27 2011
New Revision: 50635

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50635&view=rev
Log:
Add simple validation of type value. 

Modified:
    trunk/src/tools/schema/error_container.cpp
    trunk/src/tools/schema/error_container.hpp
    trunk/src/tools/schema/sourceparser.cpp

Modified: trunk/src/tools/schema/error_container.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tools/schema/error_container.cpp?rev=50635&r1=50634&r2=50635&view=diff
==============================================================================
--- trunk/src/tools/schema/error_container.cpp (original)
+++ trunk/src/tools/schema/error_container.cpp Sat Aug  6 23:32:27 2011
@@ -63,6 +63,14 @@
        s << file << ":" << line <<": Tag "<< name <<" has no parent \n";
        list_.push_back(s.str());
 }
+void class_error_container::wrong_type_error(const std::string & file,int line,
+                                                                               
         const std::string & name,
+                                                                               
         const std::string & value){
+       std::ostringstream s;
+       s << file << ":" << line <<": Type "<< name <<" has wrong value:"<<
+                       value <<". Cannot create a regex\n";
+       list_.push_back(s.str());
+}
 
 void class_error_container::add_type_error(const std::string &file,int line,
                                                                                
   const std::string &type){

Modified: trunk/src/tools/schema/error_container.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tools/schema/error_container.hpp?rev=50635&r1=50634&r2=50635&view=diff
==============================================================================
--- trunk/src/tools/schema/error_container.hpp (original)
+++ trunk/src/tools/schema/error_container.hpp Sat Aug  6 23:32:27 2011
@@ -95,7 +95,15 @@
         */
        void add_orphan_error(const std::string & file,int line,
                                                  const std::string & name);
-
+       /**
+        * Generate and put GCC-style error message about wrong type value
+        * @param file  Filename
+        * @param line  Number with error
+        * @param name  Name of type
+        * @param value Name of value
+        */
+       void wrong_type_error(const std::string & file,int line,
+                                                 const std::string & 
name,const std::string & value);
        /**
         * Generate and put GCC-style error message about unknown type to type 
cache
         * @param file Filename

Modified: trunk/src/tools/schema/sourceparser.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tools/schema/sourceparser.cpp?rev=50635&r1=50634&r2=50635&view=diff
==============================================================================
--- trunk/src/tools/schema/sourceparser.cpp (original)
+++ trunk/src/tools/schema/sourceparser.cpp Sat Aug  6 23:32:27 2011
@@ -545,10 +545,17 @@
        bool res = boost::regex_match(s,sub,allow_type);
        if (res){
                std::string name = sub[1];
+               std::string value = sub[2];
+               try{
+                       boost::regex tmp (value);
+               }catch(std::exception ){
+                       errors_.wrong_type_error(input_,line_,name,value);
+                       return true;
+               }
                if(types_.find(name)!=types_.end()){
                        errors_.overriding_type_error(input_,line_,name);
                }
-               types_[name]=sub[2];
+               types_[name]=value;
                errors_.remove_type_errors(name);
        }
        return res;


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to