https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112113
Revision: 112113
Author: gwicke
Date: 2012-02-22 15:59:11 +0000 (Wed, 22 Feb 2012)
Log Message:
-----------
Add some support for functionhooks in test parser and parserTests.js, and
tweak a few parser functions.
Modified Paths:
--------------
trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
trunk/extensions/VisualEditor/tests/parser/parserTests.js
trunk/extensions/VisualEditor/tests/parser/parserTests.pegjs
Modified:
trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
2012-02-22 15:53:21 UTC (rev 112112)
+++ trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
2012-02-22 15:59:11 UTC (rev 112113)
@@ -7,6 +7,13 @@
* matching a lower-cased template name prefix up to the first colon will
* override that template.
*
+ * TODO: Implement these more thoroughly, and test against
+ * extensions/ParserFunction/
+ * convertTests.txt
+ * exprTests.txt
+ * funcsParserTests.txt
+ * stringFunctionTests.txt
+ *
* @author Gabriel Wicke <[email protected]>
*/
@@ -34,7 +41,7 @@
kv = kvs[i];
// XXX: tokensToString actually strips too much here! Anything
// non-stringish should not match at all.
- if ( this.manager.env.tokensToString( kv.v ) === key ) {
+ if ( this.manager.env.tokensToString( kv.v ).trim() === key ) {
// found. now look for the next entry with a non-empty
key.
for ( var j = i; j < l; j++) {
kv = kvs[j];
@@ -304,11 +311,15 @@
ParserFunctions.prototype['pf_#ifexpr'] = function ( target, argList, argDict
) {
this.manager.env.dp( '#ifexp: ' + JSON.stringify( argList ) );
var res;
- try {
- var f = new Function ( 'return (' + target + ')' );
- res = f();
- } catch ( e ) {
- return [ 'class="error" in expression ' + target ];
+ if ( target ) {
+ try {
+ var f = new Function ( 'return (' + target + ')' );
+ res = f();
+ } catch ( e ) {
+ return [ 'class="error" in expression ' + target ];
+ }
+ } else {
+ res = target;
}
if ( res ) {
return ( argList[0] && argList[0].v ) || [];
@@ -320,16 +331,20 @@
if ( target.indexOf( 'class="error"' ) >= 0 ) {
return ( argList[0] && argList[0].v ) || [];
} else {
- return ( argList[1] && argList[1].v ) || [];
+ return argList[1] && argList[1].v || [ target ] ;
}
};
ParserFunctions.prototype['pf_#expr'] = function ( target, argList, argDict ) {
var res;
- try {
- var f = new Function ( 'return (' + target + ')' );
- res = f();
- } catch ( e ) {
- return [ 'class="error" in expression ' + target ];
+ if ( target ) {
+ try {
+ var f = new Function ( 'return (' + target + ')' );
+ res = f();
+ } catch ( e ) {
+ return [ 'class="error" in expression ' + target ];
+ }
+ } else {
+ res = '';
}
return [ res.toString() ];
};
Modified: trunk/extensions/VisualEditor/tests/parser/parserTests.js
===================================================================
--- trunk/extensions/VisualEditor/tests/parser/parserTests.js 2012-02-22
15:53:21 UTC (rev 112112)
+++ trunk/extensions/VisualEditor/tests/parser/parserTests.js 2012-02-22
15:59:11 UTC (rev 112113)
@@ -180,7 +180,7 @@
console.log(e2);
}
- this.cases = this.getTests();
+ this.cases = this.getTests() || [];
this.articles = {};
@@ -592,6 +592,11 @@
this.comments.push( item.comment );
process.nextTick(
this.processCase.bind( this, i + 1 ) );
break;
+ case 'hooks':
+ console.warn('parserTests: Unhandled
hook ' + JSON.stringify( item ) );
+ case 'functionhooks':
+ console.warn('parserTests: Unhandled
functionhook '
+ + JSON.stringify( item
) );
default:
this.comments = [];
process.nextTick(
this.processCase.bind( this, i + 1 ) );
Modified: trunk/extensions/VisualEditor/tests/parser/parserTests.pegjs
===================================================================
--- trunk/extensions/VisualEditor/tests/parser/parserTests.pegjs
2012-02-22 15:53:21 UTC (rev 112112)
+++ trunk/extensions/VisualEditor/tests/parser/parserTests.pegjs
2012-02-22 15:59:11 UTC (rev 112113)
@@ -34,7 +34,8 @@
article /
test /
line /
- hooks
+ hooks /
+ functionhooks
@@ -77,7 +78,25 @@
end_article =
"!!" ws? "endarticle" ws? eol
+// function hooks
+functionhooks = start_functionhooks text:text end_functionhooks
+{
+ return {
+ type: 'functionhooks',
+ text: text
+ }
+}
+
+start_functionhooks =
+ "!!" ws? "functionhooks" ":"? ws? eol
+
+end_functionhooks =
+ "!!" ws? "endfunctionhooks" ":"? ws? eol
+
+end_test =
+ "!!" ws? "end" ws? eol
+
test =
start_test
title:text
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs