Author: elias
Date: Tue Apr  8 20:48:02 2008
New Revision: 25688

URL: http://svn.gna.org/viewcvs/wesnoth?rev=25688&view=rev
Log:
Made wmlunits 250% faster.

Modified:
    trunk/data/tools/wesnoth/wmlparser.py
    trunk/data/tools/wmlunits

Modified: trunk/data/tools/wesnoth/wmlparser.py
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth/wmlparser.py?rev=25688&r1=25687&r2=25688&view=diff
==============================================================================
--- trunk/data/tools/wesnoth/wmlparser.py (original)
+++ trunk/data/tools/wesnoth/wmlparser.py Tue Apr  8 20:48:02 2008
@@ -64,6 +64,9 @@
 
         self.textdomain = ""
 
+        # Callback which is called for each macro. If it returns False, the
+        # macro is ignored.
+        self.macro_callback = None
         self.macro_not_found_callback = None
         self.no_macros = False
         
@@ -290,6 +293,10 @@
 
         preserve = macro
         macro = macro[:-1] # Get rid of final }
+        
+        if self.macro_callback:
+            if not self.macro_callback(macro): return None
+        
         # If the macro starts with ~, assume a file in userdata.
         if macro[0] == "~":
             if self.user_dir:

Modified: trunk/data/tools/wmlunits
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wmlunits?rev=25688&r1=25687&r2=25688&view=diff
==============================================================================
--- trunk/data/tools/wmlunits (original)
+++ trunk/data/tools/wmlunits Tue Apr  8 20:48:02 2008
@@ -33,7 +33,7 @@
         parser.parse_top(None)
         self.core_macros = parser.macros
                 
-    def parse(self, text_to_parse):
+    def parse(self, text_to_parse, ignore_macros = None):
         # Create the real parser.
         parser = wmlparser.Parser(datadir)
         parser.do_preprocessor_logic = True
@@ -43,6 +43,9 @@
         # Suppress complaints about undefined terrain macros
         parser.set_macro_not_found_callback(lambda wmlparser, name, params:
         name.startswith("TERRAIN") or name == "DISABLE_TRANSITIONS")
+        
+        if ignore_macros:
+            parser.macro_callback = ignore_macros
 
         # Create a WML root element and parse the given text into it.
         WML = wmldata.DataSub("WML")
@@ -116,7 +119,8 @@
 
             # Re-parse, this time with the define defined.
             WML = self.parser.parse(
-                "#define %s\n#enddef\n%s" % (define, text_to_parse))
+                "#define %s\n#enddef\n%s" % (define, text_to_parse),
+                ignore_macros = lambda x: x.find("%s/scenarios" % campaign) == 
-1)
             # This time, it oughta work.
             units = WML.get_first("+units")
             if not units:


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

Reply via email to