Author: ai0867
Date: Mon Sep 29 10:38:16 2008
New Revision: 29756
URL: http://svn.gna.org/viewcvs/wesnoth?rev=29756&view=rev
Log:
* Extended wmlgrammar to allow references to the content of other tags.
Modified:
trunk/data/tools/wesnoth/wmlgrammar.py
trunk/data/tools/wmltest
Modified: trunk/data/tools/wesnoth/wmlgrammar.py
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth/wmlgrammar.py?rev=29756&r1=29755&r2=29756&view=diff
==============================================================================
--- trunk/data/tools/wesnoth/wmlgrammar.py (original)
+++ trunk/data/tools/wesnoth/wmlgrammar.py Mon Sep 29 10:38:16 2008
@@ -5,8 +5,12 @@
This tuple consists of the following:
-A list of all subtags recognised in the tag.
-A list of all keys recognised in the tag.
+
+Instead of a tuple, it can instead contain a single string,
+ which points to the tag (dictionary key) whose contents should be used.
"""
-grammar = {
+class Grammar:
+ _grammar = {
# This is the top-level pseudo-tag that everything is a child of.
# It should have no keys
'WML' : (
@@ -48,4 +52,10 @@
[ 'sections', 'topics', ]),
}
-
+ def grammar(self):
+ out = {}
+ for key in self._grammar.keys():
+ out.update( { key : self._grammar[key] } )
+ while isinstance(self._grammar[key], str):
+ out.update( { key : self._grammar[self._grammar[key]] } )
+ return out
Modified: trunk/data/tools/wmltest
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wmltest?rev=29756&r1=29755&r2=29756&view=diff
==============================================================================
--- trunk/data/tools/wmltest (original)
+++ trunk/data/tools/wmltest Mon Sep 29 10:38:16 2008
@@ -22,6 +22,7 @@
def __init__(self, wmltree, verbosity):
self.wmltree = wmltree
self.verbosity = verbosity
+ self.grammar = wmlgrammar.Grammar().grammar()
def test(self, tag=None, depth=0):
if not tag:
tag = self.wmltree
@@ -29,12 +30,12 @@
print "%sTesting tag %s" % (depth * ' ', tag.name, )
for item in tag.data:
if isinstance(item, wmldata.DataSub):
- if item.name in wmlgrammar.grammar[tag.name][0]:
+ if item.name in self.grammar[tag.name][0]:
self.test(item, depth + 1)
else:
print "Found tag %s which is meaningless in %s" %
(item.name, tag.name)
elif isinstance(item, wmldata.DataText):
- if item.name in wmlgrammar.grammar[tag.name][1]:
+ if item.name in self.grammar[tag.name][1]:
if self.verbosity > 2:
print "%sFound key %s with contents %s" % ((depth + 1)
* ' ', item.name, item.data)
else:
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits