mail[Wesnoth-commits] r20287 - /trunk/data/tools/wesnoth/wmliterator.py


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

Header


Content

Posted by patrick_X99 on September 11, 2007 - 00:28:
Author: sapient
Date: Tue Sep 11 00:27:29 2007
New Revision: 20287

URL: http://svn.gna.org/viewcvs/wesnoth?rev=20287&view=rev
Log:
add a __main__ and fix the bug with closing [+tag]

Modified:
    trunk/data/tools/wesnoth/wmliterator.py

Modified: trunk/data/tools/wesnoth/wmliterator.py
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth/wmliterator.py?rev=20287&r1=20286&r2=20287&view=diff
==============================================================================
--- trunk/data/tools/wesnoth/wmliterator.py (original)
+++ trunk/data/tools/wesnoth/wmliterator.py Tue Sep 11 00:27:29 2007
@@ -5,7 +5,7 @@
 import sys, re
 keyPattern = re.compile('(\w+)(,\s?\w+)*\s*=')
 keySplit = re.compile(r'[=,\s]')
-tagPattern = re.compile(r'(^|(?<![\w\|]))(\[.*?\])')
+tagPattern = re.compile(r'(^|(?<![\w\|\}]))(\[.*?\])')
 macroOpenPattern = re.compile(r'(\{[^\s\}]*)')
 macroClosePattern = re.compile(r'\}')
 
@@ -67,7 +67,8 @@
                 pass
         elif not isDirective(scopes[-1][0]):
             closed = scopes.pop()
-            if ((isOpener(closed[0]) and closerElement != '[/'+closed[0][1:])
+            if ((isOpener(closed[0]) and closerElement != '[/'+closed[0][1:]
+                 and '+'+closerElement != closed[0][1]+'[/'+closed[0][2:])
             or (closed[0].startswith('{') and 
closerElement.find('macro')<0)):
                 print >>sys.stderr, 'wmliterator: reached', closerElement, 
'before closing scope', closed
                 scopes.append(closed) # to reduce additional errors 
(hopefully)
@@ -226,4 +227,28 @@
             return WmlIterator(self.lines)
         return WmlIterator(self.lines, self.scopes[-1][1], self.scopes[-1])
 
+if __name__ == '__main__':
+    """Perform a test run on a file or directory"""
+    import os, glob
+    didSomething = False
+    print 'Current directory is', os.getcwd()
+    flist = glob.glob(os.path.join(os.getcwd(), raw_input('Which file(s) 
would you like to test?\n')))
+    while flist:
+        fname = flist.pop()
+        if os.path.isdir(fname):
+            flist += glob.glob(fname + os.path.sep + '*')
+            continue
+        if not os.path.isfile(fname) or os.path.splitext(fname)[1] != '.cfg':
+            continue
+        print 'Reading', fname+'...'
+        didSomething = True
+        f = open(fname)
+        itor = WmlIterator(f.readlines())
+        for i in itor:
+            pass
+        f.close()
+        print itor.lineno + itor.span, 'lines read.'
+    if not didSomething:
+        print 'That is not a valid .cfg file'
+
 # wmliterator.py ends here




Related Messages


Powered by MHonArc, Updated Tue Sep 11 01:00:25 2007