mail[Wesnoth-commits] r24382 - in /trunk/data/tools: wesnoth/wmltools.py wmlscope


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

Header


Content

Posted by esr on March 07, 2008 - 11:19:
Author: esr
Date: Fri Mar  7 11:19:25 2008
New Revision: 24382

URL: http://svn.gna.org/viewcvs/wesnoth?rev=24382&view=rev
Log:
Teach wmlscope how to detect duplicate unit IDs.  Fix some trivial instances.

Modified:
    trunk/data/tools/wesnoth/wmltools.py
    trunk/data/tools/wmlscope

Modified: trunk/data/tools/wesnoth/wmltools.py
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth/wmltools.py?rev=24382&r1=24381&r2=24382&view=diff
==============================================================================
--- trunk/data/tools/wesnoth/wmltools.py (original)
+++ trunk/data/tools/wesnoth/wmltools.py Fri Mar  7 11:19:25 2008
@@ -196,6 +196,7 @@
 class CrossRef:
     macro_reference = re.compile(r"\{([A-Z_][A-Za-z0-9_:]*)(?!\.)\b")
     file_reference =  re.compile(r"[A-Za-z0-9{}.][A-Za-z0-9_/+{}.-]*\.(" + 
"|".join(resource_extensions) + ")(?=(~.*)?)")
+    tag_parse = re.compile("\s*([a-z_]+)\s*=(.*)") 
     def mark_matching_resources(self, pattern, fn, n):
         "Mark all definitions matching a specified pattern with a reference."
         pattern = pattern.replace("+", r"\+")
@@ -241,6 +242,7 @@
         self.fileref = {}
         self.noxref = False
         self.properties = {}
+        self.unit_ids = {}
         if warnlevel >=2:
             print "*** Beginning definition-gathering pass..."
         for (namespace, filename) in self.filelist.generator():
@@ -252,6 +254,7 @@
                 # It's a WML file, scan for macro definitions
                 dfp = open(filename)
                 state = "outside"
+                latch_unit = in_base_unit = False
                 for (n, line) in enumerate(dfp):
                     if warnlevel > 1:
                         print `line`[1:-1]
@@ -311,6 +314,22 @@
                         else:
                             print "%s: unbalanced #undef on %s" \
                                   % (Reference(namespace, filename, n+1), 
name)
+                    elif '[unit]' in line:
+                        latch_unit = True
+                    elif '[/unit]' in line:
+                        latch_unit = False
+                    elif '[base_unit]' in line:
+                        in_base_unit = True
+                    elif '[/base_unit]' in line:
+                        in_base__unit = True
+                    elif latch_unit and not in_base_unit and "id" in line:
+                        m = CrossRef.tag_parse.search(line)
+                        if m and m.group(1) == "id":
+                            uid = m.group(2)
+                            if uid not in self.unit_ids:
+                                self.unit_ids[uid] = []
+                            self.unit_ids[uid].append(Reference(namespace, 
filename, n+1))
+                            latch_unit= False
                 dfp.close()
             elif filename.endswith(".def"):
                 # It's a list of names to be considered defined

Modified: trunk/data/tools/wmlscope
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wmlscope?rev=24382&r1=24381&r2=24382&view=diff
==============================================================================
--- trunk/data/tools/wmlscope (original)
+++ trunk/data/tools/wmlscope Fri Mar  7 11:19:25 2008
@@ -136,7 +136,7 @@
                 print "Resource %s is used in %d files:" % (defloc, nrefs)
             defloc.dump_references()
     def unresdump(self):
-        "Report unresolved references and arity mismatches."
+        "Report unresolved references arity mismatches, duplicate unit IDs."
         # First the unresolved references
         if len(self.unresolved) == 0 and len(self.missing) == 0:
             print "# No unresolved references"
@@ -164,6 +164,12 @@
                             print '"%s", line %d: %s(%s) with signature 
(%s)' % (file, ln, n, ", ".join(args), ", ".join(map(lambda f, a: "%s=%s" % 
(f, actualtype(a)), m.args, args)))
                         except AttributeError:
                             print '"%s", line %d: internal error in 
reporter' % (file, ln)
+        # Then the unit IDs
+        for (key, value) in self.unit_ids.items():
+            if len(value) > 1:
+                print "%s: occurs %d times as unit ID" % (key, len(value))
+                for ref in value:
+                    print "%s: %s" % (ref, key)
     def typelist(self, branch):
         "Dump actual and formal aruments for macros in specified file"
         already_seen = []




Related Messages


Powered by MHonArc, Updated Fri Mar 07 12:01:17 2008