r111113 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111112‎ | r111113 | r111114 >
Date:22:27, 9 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Some comments and reshuffling in the grammar, and a typo in the
AttributeExpander.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -338,61 +338,9 @@
339339 / ' ' & ':' { return "\u00a0"; }
340340 / t:text_char )+
341341
342 -directive
343 - = comment
344 - / tplarg_or_template
345 - / htmlentity
346342
347 -spaceless_preprocessor_text
348 - = r:( t:[^'<~[{\n\r|!\]}\t &=]+ { return t.join(''); }
349 - / directive
350 - / !inline_breaks !' ' text_char )+ {
351 - return flatten_string ( r );
352 - }
353343
354 -link_preprocessor_text
355 - = r:( t:[^'<~[{\n\r|!\]}\t &="']+ { return t.join(''); }
356 - / directive
357 - / urlencoded_char
358 - / !inline_breaks no_punctuation_char
359 - / s:[.:,] !(space / eolf) { return s }
360 - / [&%] )+ {
361 - return flatten_string ( r );
362 - }
363344
364 -attribute_preprocessor_text
365 - = r:( ts:(!inline_breaks t:[^=<>{\n\r&'"\t ] {return t})+ { return ts.join(''); }
366 - / directive
367 - / !inline_breaks [&%] )* {
368 - //console.log('prep');
369 - return flatten_string ( r );
370 - }
371 -attribute_preprocessor_text_single
372 - = r:( t:[^>{\n\r&']+ { return t.join(''); }
373 - / directive
374 - / !inline_breaks [&%] )* {
375 - return flatten_string ( r );
376 - }
377 -attribute_preprocessor_text_double
378 - = r:( t:[^>{\n\r&"]+ { return t.join(''); }
379 - / directive
380 - / !inline_breaks [&%] )* {
381 - //console.log( 'double:' + pp(r) );
382 - return flatten_string ( r );
383 - }
384 -
385 -// Plain text, but can contain templates, template arguments, comments etc-
386 -// all stuff that is normally handled by the preprocessor
387 -// Returns either a list of tokens, or a plain string (if nothing is to be
388 -// processed).
389 -preprocessor_text
390 - = r:( t:[^<~[{\n\r\t|!\]} &=]+ { return t.join(''); }
391 - / directive
392 - / !inline_breaks text_char )+ {
393 - return flatten ( r );
394 - }
395 -
396 -
397345 /*
398346 '//', // for protocol-relative URLs, but not in text!
399347 'ftp://',
@@ -480,6 +428,67 @@
481429
482430 eolf = newline / eof
483431
 432+
 433+// 'Preprocessor' directive- higher-level things that can occur in otherwise
 434+// plain-text content.
 435+directive
 436+ = comment
 437+ / tplarg_or_template
 438+ / htmlentity
 439+
 440+// Plain text, but can contain templates, template arguments, comments etc-
 441+// all stuff that is normally handled by the preprocessor
 442+// Returns either a list of tokens, or a plain string (if nothing is to be
 443+// processed).
 444+preprocessor_text
 445+ = r:( t:[^<~[{\n\r\t|!\]} &=]+ { return t.join(''); }
 446+ / directive
 447+ / !inline_breaks text_char )+ {
 448+ return flatten ( r );
 449+ }
 450+
 451+spaceless_preprocessor_text
 452+ = r:( t:[^'<~[{\n\r|!\]}\t &=]+ { return t.join(''); }
 453+ / directive
 454+ / !inline_breaks !' ' text_char )+ {
 455+ return flatten_string ( r );
 456+ }
 457+
 458+link_preprocessor_text
 459+ = r:( t:[^'<~[{\n\r|!\]}\t &="']+ { return t.join(''); }
 460+ / directive
 461+ / urlencoded_char
 462+ / !inline_breaks no_punctuation_char
 463+ / s:[.:,] !(space / eolf) { return s }
 464+ / [&%] )+ {
 465+ return flatten_string ( r );
 466+ }
 467+
 468+// Attribute values with preprocessor support
 469+attribute_preprocessor_text
 470+ = r:( ts:(!inline_breaks t:[^=<>{\n\r&'"\t ] {return t})+ { return ts.join(''); }
 471+ / directive
 472+ / !inline_breaks [&%] )* {
 473+ //console.log('prep');
 474+ return flatten_string ( r );
 475+ }
 476+attribute_preprocessor_text_single
 477+ = r:( t:[^{&']+ { return t.join(''); }
 478+ / directive
 479+ / !inline_breaks [{&] )* {
 480+ return flatten_string ( r );
 481+ }
 482+attribute_preprocessor_text_double
 483+ = r:( t:[^{&"]+ { return t.join(''); }
 484+ / directive
 485+ / !inline_breaks [{&] )* {
 486+ //console.log( 'double:' + pp(r) );
 487+ return flatten_string ( r );
 488+ }
 489+
 490+
 491+// A document (start production) is a sequence of toplevelblocks. Tokens are
 492+// emitted in chunks per toplevelblock to avoid buffering the full document.
484493 toplevelblock
485494 = & { blockStart = pos; return true; } b:block {
486495 b = flatten(b);
@@ -496,14 +505,13 @@
497506 bs.attribs.push(new KV('data-sourcePos', blockStart + ':' + pos));
498507 //console.log( 'toplevelblock: ' + pp( bs ));
499508 }
500 - // XXX: only run this for lines that actually need it!
501 - //b.push({type: 'NEWLINE'});
502 - // Move this to a token stream transform!
503 - //console.log('about to emit' + pp(self));
504 - //console.log( '__parseArgs call: ' + pp( b ));
 509+
 510+ // Emit tokens for this toplevelblock. This feeds a chunk to the parser
 511+ // pipeline.
505512 __parseArgs[2]( flatten( b ) );
506513
507 - //return [];
 514+ // We don't return any tokens to the start production to save memory. We
 515+ // just emitted them already to our consumers.
508516 return true;
509517 }
510518
@@ -549,6 +557,9 @@
550558 / pre
551559
552560
 561+// A paragraph. We don't emit 'p' tokens to avoid issues with template
 562+// transclusions, <p> tags in the source and the like. Instead, we perform
 563+// some paragraph wrapping on the DOM.
553564 para
554565 = s1:sol s2:sol c:inlineline {
555566 return s1.concat(s2, /* [new TagTk('p')],*/ c);
@@ -896,13 +907,13 @@
897908 }
898909 } else {
899910 if (trail) {
900 - textTokens = target.concat( [ trail.join('') ] );
 911+ textTokens = $.extend(true, [], target).concat( [ trail.join('') ] );
901912 } else {
902913 // copy list
903 - textTokens = target.concat([]);
 914+ textTokens = $.extend(true, [], target);
904915 }
905916 }
906 - //console.log( "XXX:" + pp(obj) );
 917+ //console.log( "XXX:" + pp([obj].concat(textTokens, [new EndTagTk( 'a' )])) );
907918 return [obj].concat(textTokens, [new EndTagTk( 'a' )]);
908919 }
909920
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js
@@ -1,8 +1,7 @@
22 /**
3 - * Geniric attribute expansion handler.
 3+ * Generic attribute expansion handler.
44 *
55 * @author Gabriel Wicke <gwicke@wikimedia.org>
6 - * @author Brion Vibber <brion@wikimedia.org>
76 */
87 var $ = require('jquery'),
98 request = require('request'),
@@ -77,7 +76,8 @@
7877 AttributeExpander.prototype._returnAttributes = function ( expandData,
7978 attributes )
8079 {
81 - this.manager.env.dp( 'AttributeExpander._returnAttributes: ' + JSON.stringify(attributes) );
 80+ this.manager.env.dp( 'AttributeExpander._returnAttributes: ' +
 81+ JSON.stringify(attributes) );
8282 // Remove the target from the attributes
8383 expandData.token.attribs = attributes;
8484 if ( expandData.async ) {

Status & tagging log