r91336 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91335‎ | r91336 | r91337 >
Date:23:59, 1 July 2011
Author:brion
Status:deferred
Tags:
Comment:
ParserPlayground: handle named refs a bit better, fix for 'content' item in template params
Modified paths:
  • /trunk/extensions/ParserPlayground/modules/ext.parserPlayground.renderer.js (modified) (history)
  • /trunk/extensions/ParserPlayground/modules/ext.parserPlayground.serializer.js (modified) (history)
  • /trunk/extensions/ParserPlayground/modules/pegParser.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.renderer.js
@@ -22,6 +22,16 @@
2323 }, inspectorMap);
2424 });
2525 };
 26+ var extensionAttribute = function(node, name) {
 27+ var lname = name.toLowerCase();
 28+ var match = null;
 29+ $.each(node.params, function(i, param) {
 30+ if (param.name.toLowerCase() == lname) {
 31+ match = param;
 32+ }
 33+ });
 34+ return match ? match.text : null;
 35+ }
2636 var node;
2737 if (typeof tree == "string") {
2838 // hack
@@ -107,9 +117,27 @@
108118 // @fixme names etc?
109119 if (self.context.refs === undefined) {
110120 self.context.refs = [];
 121+ self.context.refsByName = {};
111122 }
112 - self.context.refs.push(tree);
113 - var refNum = self.context.refs.length;
 123+ var refNum;
 124+ var name = extensionAttribute(tree, 'name');
 125+ if (name !== null && name in self.context.refsByName) {
 126+ // Already seen!
 127+ refNum = self.context.refsByName[name];
 128+ var origRef = self.context.refs[refNum - 1];
 129+ if ('content' in tree && tree.content && !('content' in origRef && origRef.content)) {
 130+ // Earlier one was empty; replace it with this one.
 131+ self.context.refs[refNum - 1] = tree;
 132+ }
 133+ } else {
 134+ // New one!
 135+ self.context.refs.push(tree);
 136+ refNum = self.context.refs.length;
 137+ if (name !== null) {
 138+ self.context.refsByName[name] = refNum;
 139+ }
 140+ }
 141+
114142 var ref = $('<span class="ref parseNode">[</span>');
115143 $('<a></a>')
116144 .text(refNum + '')
@@ -128,6 +156,10 @@
129157 if ('content' in subtree) {
130158 subParseArray(subtree.content, ref);
131159 }
 160+ ref.data('parseNode', subtree); // assign the node for the tree inspector
 161+ if (inspectorMap) {
 162+ inspectorMap.put(subtree, ref[0]); // store for reverse lookup
 163+ }
132164 references.append(ref);
133165 });
134166 node = references[0];
Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.serializer.js
@@ -98,7 +98,7 @@
9999 if ('name' in param) {
100100 src += param.name + '=';
101101 }
102 - src += subParseArray(param.contents);
 102+ src += subParseArray(param.content);
103103 }
104104 }
105105 src += '}}';
Index: trunk/extensions/ParserPlayground/modules/pegParser.pegjs.txt
@@ -165,11 +165,11 @@
166166 = name:template_param_name "=" c:template_param_text {
167167 return {
168168 name: name,
169 - contents: c
 169+ content: c
170170 };
171171 } / c:template_param_text {
172172 return {
173 - contents: c
 173+ content: c
174174 };
175175 }
176176

Follow-up revisions

RevisionCommit summaryAuthorDate
r91337followup r91336 - fix misspell in renderer toobrion00:01, 2 July 2011

Status & tagging log