Index: trunk/extensions/VisualEditor/tests/parser/parserTests.pegjs |
— | — | @@ -34,7 +34,8 @@ |
35 | 35 | article / |
36 | 36 | test / |
37 | 37 | line / |
38 | | - hooks |
| 38 | + hooks / |
| 39 | + functionhooks |
39 | 40 | |
40 | 41 | |
41 | 42 | |
— | — | @@ -77,7 +78,25 @@ |
78 | 79 | end_article = |
79 | 80 | "!!" ws? "endarticle" ws? eol |
80 | 81 | |
| 82 | +// function hooks |
81 | 83 | |
| 84 | +functionhooks = start_functionhooks text:text end_functionhooks |
| 85 | +{ |
| 86 | + return { |
| 87 | + type: 'functionhooks', |
| 88 | + text: text |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +start_functionhooks = |
| 93 | + "!!" ws? "functionhooks" ":"? ws? eol |
| 94 | + |
| 95 | +end_functionhooks = |
| 96 | + "!!" ws? "endfunctionhooks" ":"? ws? eol |
| 97 | + |
| 98 | +end_test = |
| 99 | + "!!" ws? "end" ws? eol |
| 100 | + |
82 | 101 | test = |
83 | 102 | start_test |
84 | 103 | title:text |
Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js |
— | — | @@ -180,7 +180,7 @@ |
181 | 181 | console.log(e2); |
182 | 182 | } |
183 | 183 | |
184 | | - this.cases = this.getTests(); |
| 184 | + this.cases = this.getTests() || []; |
185 | 185 | |
186 | 186 | this.articles = {}; |
187 | 187 | |
— | — | @@ -592,6 +592,11 @@ |
593 | 593 | this.comments.push( item.comment ); |
594 | 594 | process.nextTick( this.processCase.bind( this, i + 1 ) ); |
595 | 595 | break; |
| 596 | + case 'hooks': |
| 597 | + console.warn('parserTests: Unhandled hook ' + JSON.stringify( item ) ); |
| 598 | + case 'functionhooks': |
| 599 | + console.warn('parserTests: Unhandled functionhook ' |
| 600 | + + JSON.stringify( item ) ); |
596 | 601 | default: |
597 | 602 | this.comments = []; |
598 | 603 | process.nextTick( this.processCase.bind( this, i + 1 ) ); |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js |
— | — | @@ -7,6 +7,13 @@ |
8 | 8 | * matching a lower-cased template name prefix up to the first colon will |
9 | 9 | * override that template. |
10 | 10 | * |
| 11 | + * TODO: Implement these more thoroughly, and test against |
| 12 | + * extensions/ParserFunction/ |
| 13 | + * convertTests.txt |
| 14 | + * exprTests.txt |
| 15 | + * funcsParserTests.txt |
| 16 | + * stringFunctionTests.txt |
| 17 | + * |
11 | 18 | * @author Gabriel Wicke <gwicke@wikimedia.org> |
12 | 19 | */ |
13 | 20 | |
— | — | @@ -34,7 +41,7 @@ |
35 | 42 | kv = kvs[i]; |
36 | 43 | // XXX: tokensToString actually strips too much here! Anything |
37 | 44 | // non-stringish should not match at all. |
38 | | - if ( this.manager.env.tokensToString( kv.v ) === key ) { |
| 45 | + if ( this.manager.env.tokensToString( kv.v ).trim() === key ) { |
39 | 46 | // found. now look for the next entry with a non-empty key. |
40 | 47 | for ( var j = i; j < l; j++) { |
41 | 48 | kv = kvs[j]; |
— | — | @@ -304,11 +311,15 @@ |
305 | 312 | ParserFunctions.prototype['pf_#ifexpr'] = function ( target, argList, argDict ) { |
306 | 313 | this.manager.env.dp( '#ifexp: ' + JSON.stringify( argList ) ); |
307 | 314 | var res; |
308 | | - try { |
309 | | - var f = new Function ( 'return (' + target + ')' ); |
310 | | - res = f(); |
311 | | - } catch ( e ) { |
312 | | - return [ 'class="error" in expression ' + target ]; |
| 315 | + if ( target ) { |
| 316 | + try { |
| 317 | + var f = new Function ( 'return (' + target + ')' ); |
| 318 | + res = f(); |
| 319 | + } catch ( e ) { |
| 320 | + return [ 'class="error" in expression ' + target ]; |
| 321 | + } |
| 322 | + } else { |
| 323 | + res = target; |
313 | 324 | } |
314 | 325 | if ( res ) { |
315 | 326 | return ( argList[0] && argList[0].v ) || []; |
— | — | @@ -320,16 +331,20 @@ |
321 | 332 | if ( target.indexOf( 'class="error"' ) >= 0 ) { |
322 | 333 | return ( argList[0] && argList[0].v ) || []; |
323 | 334 | } else { |
324 | | - return ( argList[1] && argList[1].v ) || []; |
| 335 | + return argList[1] && argList[1].v || [ target ] ; |
325 | 336 | } |
326 | 337 | }; |
327 | 338 | ParserFunctions.prototype['pf_#expr'] = function ( target, argList, argDict ) { |
328 | 339 | var res; |
329 | | - try { |
330 | | - var f = new Function ( 'return (' + target + ')' ); |
331 | | - res = f(); |
332 | | - } catch ( e ) { |
333 | | - return [ 'class="error" in expression ' + target ]; |
| 340 | + if ( target ) { |
| 341 | + try { |
| 342 | + var f = new Function ( 'return (' + target + ')' ); |
| 343 | + res = f(); |
| 344 | + } catch ( e ) { |
| 345 | + return [ 'class="error" in expression ' + target ]; |
| 346 | + } |
| 347 | + } else { |
| 348 | + res = ''; |
334 | 349 | } |
335 | 350 | return [ res.toString() ]; |
336 | 351 | }; |