mail[Wesnoth-commits] r40172 - in /branches/fendrin_gui_stuff/src: CMakeLists.txt filesystem.hpp formatter.hpp wml/wml_parser.cpp wml/wml_schema.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by fabianmueller5 on December 07, 2009 - 20:47:
Author: fendrin
Date: Mon Dec  7 20:47:30 2009
New Revision: 40172

URL: http://svn.gna.org/viewcvs/wesnoth?rev=40172&view=rev
Log:
Made the frogatto wml parser compile.

Modified:
    branches/fendrin_gui_stuff/src/CMakeLists.txt
    branches/fendrin_gui_stuff/src/filesystem.hpp
    branches/fendrin_gui_stuff/src/formatter.hpp
    branches/fendrin_gui_stuff/src/wml/wml_parser.cpp
    branches/fendrin_gui_stuff/src/wml/wml_schema.cpp

Modified: branches/fendrin_gui_stuff/src/CMakeLists.txt
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_gui_stuff/src/CMakeLists.txt?rev=40172&r1=40171&r2=40172&view=diff
==============================================================================
--- branches/fendrin_gui_stuff/src/CMakeLists.txt (original)
+++ branches/fendrin_gui_stuff/src/CMakeLists.txt Mon Dec  7 20:47:30 2009
@@ -198,6 +198,18 @@
     ai/testing/stage_rca.cpp
     ai/testing/stage_fallback.cpp
     ai/testing.cpp
+    wml/wml_formula_adapter.cpp
+    wml/wml_modify.cpp 
+    wml/wml_node.cpp   
+    wml/wml_preprocessor.cpp
+    wml/wml_schema.cpp 
+    wml/wml_utils.cpp 
+    wml/wml_parser.cpp  
+    wml/wml_parser_test.cpp  
+    wml/wml_writer.cpp
+    wml/string_utils.cpp
+    wml/unit_test.cpp
+    wml/preprocessor.cpp
     animated_game.cpp
     attack_prediction.cpp
     attack_prediction_display.cpp

Modified: branches/fendrin_gui_stuff/src/filesystem.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_gui_stuff/src/filesystem.hpp?rev=40172&r1=40171&r2=40172&view=diff
==============================================================================
--- branches/fendrin_gui_stuff/src/filesystem.hpp (original)
+++ branches/fendrin_gui_stuff/src/filesystem.hpp Mon Dec  7 20:47:30 2009
@@ -224,7 +224,7 @@
  * Returns the appropriate invocation for a Wesnoth-related binary, assuming
  * that it is located in the same directory as the running wesnoth binary.
  * This is just a string-transformation based on argv[0], so the returned
- * program is not guaranteed to actaully exist.  '-debug' variants are 
handled
+ * program is not guaranteed to actually exist.  '-debug' variants are 
handled
  * correctly.
  */
 std::string get_program_invocation(const std::string &program_name);

Modified: branches/fendrin_gui_stuff/src/formatter.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_gui_stuff/src/formatter.hpp?rev=40172&r1=40171&r2=40172&view=diff
==============================================================================
--- branches/fendrin_gui_stuff/src/formatter.hpp (original)
+++ branches/fendrin_gui_stuff/src/formatter.hpp Mon Dec  7 20:47:30 2009
@@ -1,4 +1,4 @@
-/* $Id$ */
+
 /*
    Copyright (C) 2007 by David White <dave.net>
    Part of the Silver Tree Project
@@ -10,41 +10,23 @@
 
    See the COPYING file for more details.
 */
-
 #ifndef FORMATTER_HPP_INCLUDED
 #define FORMATTER_HPP_INCLUDED
 
 #include <sstream>
 
-/**
- * std::ostringstream wrapper.
- *
- * ostringstream's operator<< doesn't return a ostringstream&. It returns an
- * ostream& instead. This is unfortunate, because it means that you can't do
- * something like this: (ostringstream() << n).str() to convert an integer 
to a
- * string, all in one line instead you have to use this far more tedious
- * approach:
- *  ostringstream s;
- *  s << n;
- *  s.str();
- * This class corrects this shortcoming, allowing something like this:
- *  string result = (formatter() << "blah " << n << x << " blah").str();
- */
+#include "wml/wml_value.hpp"
+
 class formatter
 {
 public:
-       formatter() :
-               stream_()
-       {
-       }
-
        template<typename T>
        formatter& operator<<(const T& o) {
                stream_ << o;
                return *this;
        }
 
-       std::string str() {
+       const std::string str() {
                return stream_.str();
        }
 
@@ -52,6 +34,13 @@
                return str().c_str();
        }
 
+       operator std::string() {
+               return stream_.str();
+       }
+
+       operator wml::value() {
+               return wml::value(stream_.str());
+       }
 private:
        std::ostringstream stream_;
 };

Modified: branches/fendrin_gui_stuff/src/wml/wml_parser.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_gui_stuff/src/wml/wml_parser.cpp?rev=40172&r1=40171&r2=40172&view=diff
==============================================================================
--- branches/fendrin_gui_stuff/src/wml/wml_parser.cpp (original)
+++ branches/fendrin_gui_stuff/src/wml/wml_parser.cpp Mon Dec  7 20:47:30 2009
@@ -18,6 +18,8 @@
 #include <stack>
 #include <string>
 #include <vector>
+
+//#include <sys>
 
 #include <string.h>
 
@@ -147,9 +149,9 @@
 
 node_ptr wml_template::call(const std::vector<std::string>& args) const
 {
-//     if(args.size() != args_.size()) {
-//             throw parse_error(formatter() << "incorrect number of 
arguments when calling '" << node_->name() << "'\n");
-//     }
+       if(args.size() != args_.size()) {
+               throw parse_error(formatter() << "incorrect number of 
arguments when calling '" << node_->name() << "'\n");
+       }
 
        return substitute(node_, args_, args);
 }
@@ -225,9 +227,9 @@
                ++i1;
        }
 
-//     if(i1 == i2) {
-//             throw parse_error(formatter() << "unexpected end of wml 
document while parsing value '" << std::string(beg,i1) << "'");
-//     }
+       if(i1 == i2) {
+               throw parse_error(formatter() << "unexpected end of wml 
document while parsing value '" << std::string(beg,i1) << "'");
+       }
 
        //strip the string, but leave it untouched if it's all whitespace.
        {
@@ -297,9 +299,9 @@
                        if(element[0] == '/') {
                                const std::string 
close_element(element.begin()+1,element.end());
                                if(nodes.empty()) {
-//                                     PARSE_ERROR("close element found when 
there are no elements");
+                                       PARSE_ERROR("close element found when 
there are no elements");
                                } else if(nodes.top().node->name() != 
close_element) {
-//                                     PARSE_ERROR("mismatch between open 
and close elements: '" << nodes.top().node->name() << "' vs '" << 
close_element << "'");
+                                       PARSE_ERROR("mismatch between open 
and close elements: '" << nodes.top().node->name() << "' vs '" << 
close_element << "'");
                                }
 
                                if(schemas.top()) {
@@ -310,7 +312,7 @@
                                nodes.pop();
                        } else {
                                if(nodes.empty() && res) {
-//                                     PARSE_ERROR("multiple root elements 
found");
+                                       PARSE_ERROR("multiple root elements 
found");
                                }
 
                                if(nodes.empty()) {
@@ -348,7 +350,7 @@
                                        const 
wml_template_map::const_iterator t =
                                                   
wml_templates.find(element);
                                        if(t == wml_templates.end()) {
-//                                             PARSE_ERROR("unrecognized 
template call: '" << element << "'\n");
+                                               PARSE_ERROR("unrecognized 
template call: '" << element << "'\n");
                                        }
 
                                        const wml::node_ptr el = 
t->second->call(args);
@@ -389,7 +391,7 @@
                                        std::string::iterator template_name =
                                           
std::find(element.begin(),element.end(),' ');
                                        if(template_name == element.end()) {
-//                                             PARSE_ERROR("no template name 
found for template '" << element << "'");
+                                               PARSE_ERROR("no template name 
found for template '" << element << "'");
                                        }
 
                                        el.reset(new 
node(std::string(element.begin(),template_name)));
@@ -403,7 +405,7 @@
                                        std::string::iterator end_args =
                                           
std::find(template_name,element.end(),')');
                                        if(beg_args == element.end() || 
end_args == element.end()) {
-//                                             PARSE_ERROR("no arg list 
found for template '" << element << "'");
+                                               PARSE_ERROR("no arg list 
found for template '" << element << "'");
                                        }
 
                                        wml_template_ptr t(new 
wml_template(el));
@@ -423,7 +425,7 @@
                                } else if(prefix == "base") {
                                        nodes.top().base_nodes[element] = el;
                                } else if(prefix != "") {
-//                                     PARSE_ERROR("unrecognized element 
prefix");
+                                       PARSE_ERROR("unrecognized element 
prefix");
                                } else if(nodes.empty()) {
                                        res = el;
                                } else {
@@ -436,7 +438,7 @@
                        }
                } else if(isalnum(*i) || *i == '_') {
                        if(nodes.empty()) {
-//                             PARSE_ERROR("attributes found at root");
+                               PARSE_ERROR("attributes found at root");
                        }
 
                        const std::string name = parse_name(i,doc.end());
@@ -462,7 +464,7 @@
                        std::string name(begin,i);
                        if(name == "import" || name == "include") {
                                if(i == doc.end()) {
-//                                     PARSE_ERROR("unexpected document end 
while importing");
+                                       PARSE_ERROR("unexpected document end 
while importing");
                                }
 
                                ++i;
@@ -473,7 +475,7 @@
 
                                const std::string filename(begin,i);
                                if(nodes.empty() && name == "import") {
-//                                     PARSE_ERROR("@import statement at top 
level");
+                                       PARSE_ERROR("@import statement at top 
level");
                                }
                                wml::node_ptr 
node(parse_wml_from_file("data/" + filename, NULL, name == "import"));
                                if(node) {
@@ -481,7 +483,7 @@
                                }
 
                        } else {
-//                             PARSE_ERROR("unrecognized @ instruction: '" 
<< name << "'");
+                               PARSE_ERROR("unrecognized @ instruction: '" 
<< name << "'");
                        }
                } else if(*i == '#') {
                        std::string::const_iterator begin_comment = i;
@@ -489,19 +491,19 @@
                        current_comment.insert(current_comment.end(), 
begin_comment, i);
                } else {
                        std::cerr << "unexpected chars: {{{" << &*i << 
"}}}\n";
-//                     PARSE_ERROR("unexpected characters in wml document");
+                       PARSE_ERROR("unexpected characters in wml document");
                }
        } // while(i != doc.end())
        } catch(const schema_error& e) {
-//             PARSE_ERROR(e.message);
+               PARSE_ERROR(e.message);
        }
 
        if(must_have_doc && !res) {
-//             PARSE_ERROR("empty wml document for filename '" << doc <<"'");
+               PARSE_ERROR("empty wml document for filename '" << doc <<"'");
        }
 
        if(nodes.empty() == false) {
-//             PARSE_ERROR("unexpected end of wml document");
+               PARSE_ERROR("unexpected end of wml document");
        }
 
        return res;
@@ -518,9 +520,8 @@
 node_ptr parse_wml_from_file(const std::string& fname, const schema* schema, 
bool must_have_doc)
 {
        try{
-               //TODO remove the next line and enable the overnext.
-               return parse_wml_internal("", "", true, schema);
-//             return parse_wml_internal(fname, 
preprocess(sys::read_file(fname)), must_have_doc, schema);
+//             TODO renamed sys::read_file() to read_file()
+               return parse_wml_internal(fname, 
preprocess(read_file(fname)), must_have_doc, schema);
 
        } catch(wml::parse_error& e) {
                ASSERT_LOG(false, "Error parsing WML in " << fname << ": " << 
e.message);

Modified: branches/fendrin_gui_stuff/src/wml/wml_schema.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_gui_stuff/src/wml/wml_schema.cpp?rev=40172&r1=40171&r2=40172&view=diff
==============================================================================
--- branches/fendrin_gui_stuff/src/wml/wml_schema.cpp (original)
+++ branches/fendrin_gui_stuff/src/wml/wml_schema.cpp Mon Dec  7 20:47:30 2009
@@ -208,7 +208,7 @@
        }
 
        if(itor == attributes_.end()) {
-//             generate_error(formatter() << "Unknown attribute: " << name);
+               generate_error(formatter() << "Unknown attribute: " << name);
        }
 
        itor->second.validate(name, value);
@@ -218,7 +218,7 @@
 {
        element_map::const_iterator itor = elements_.find(name);
        if(itor == elements_.end()) {
-//             generate_error(formatter() << "Unrecognized element: " << 
name);
+               generate_error(formatter() << "Unrecognized element: " << 
name);
        }
 
        return get(itor->second.type);
@@ -228,7 +228,7 @@
 {
        for(attribute_map::const_iterator i = attributes_.begin(); i != 
attributes_.end(); ++i) {
                if(i->second.optional == false && node->has_attr(i->first) == 
false) {
-//                     generate_error(formatter() << "Required attribute " 
<< i->first << " not found");
+                       generate_error(formatter() << "Required attribute " 
<< i->first << " not found");
                }
        }
 
@@ -242,13 +242,13 @@
                        }
 
                        if(i1 != i2) {
-//                             generate_error(formatter() << "Element " << 
i->first << " appears too many times; it should appear at most once.");
+                               generate_error(formatter() << "Element " << 
i->first << " appears too many times; it should appear at most once.");
                        }
                        break;
                }
                case ELEMENT_REQUIRED:
                        if(!node->get_child(i->first)) {
-//                             generate_error(formatter() << "Required 
element " << i->first << " not found");
+                               generate_error(formatter() << "Required 
element " << i->first << " not found");
                        }
                        break;
                case ELEMENT_REPEATED:




Related Messages


Powered by MHonArc, Updated Tue Dec 08 22:00:11 2009