r111464 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111463‎ | r111464 | r111465 >
Date:15:45, 14 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Fix named wikilink options (image options really) in template arguments, and
speed up template parameter parsing by eliminating some backtracking. 238
tests passing (unchanged).
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -1,5 +1,12 @@
2 -/* Combined Wiki (MediaWiki) and HTML tokenizer. Produces a token stream
3 -** (actually a list of tokens for now) suitable for a HTML5TreeBuilder. */
 2+/**
 3+ * Combined Wiki (MediaWiki) and HTML tokenizer based on pegjs. Emits several
 4+ * chunks of tokens (one chunk per top-level block matched) and eventually an
 5+ * end event. Tokens map to HTML tags as far as possible, with custom tokens
 6+ * used where further processing on the token stream is needed.
 7+ *
 8+ * @author Gabriel Wicke <gwicke@wikimedia.org>
 9+ * @author Brion Vibber <brion@wikimedia.org>
 10+ */
411 {
512 /* Fixme: use static functions to separate module! Unfortunately, this
613 * does not work:
@@ -586,9 +593,12 @@
587594 / & { return syntaxFlags['extlink']; } "]" { return true; }
588595 / & { return syntaxFlags['linkdesc']; } link_end { return true; }
589596 / & { return syntaxFlags['h']; } '='+ space* newline { return true; }
590 - / & { return syntaxFlags['template']; } ('|' / '}}' ) { return true; }
 597+ / & { return syntaxFlags['template']; } ('|' / '}}' ) {
 598+ //console.log( 'template break @' + pos + input.substr(pos-1, 4) );
 599+ return true;
 600+ }
591601 / & { return syntaxFlags['equal']; } '=' {
592 - //console.log( 'equal stop!' );
 602+ //console.log( 'equal stop @' + pos + input.substr(pos-1, 4) );
593603 return true;
594604 }
595605
@@ -614,7 +624,7 @@
615625 if (text.length) {
616626 out.push( text.join('') );
617627 }
618 - //dp('inline out:' + pp(out));
 628+ //console.log('inline out:' + pp(out));
619629 return out;
620630 }
621631
@@ -648,7 +658,7 @@
649659 inline_element
650660 = //& { dp('inline_element enter' + input.substr(pos, 10)); return true; }
651661 & '<' ( comment / xmlish_tag )
652 - / & '{' ( & '{{{{{' template / tplarg / template )
 662+ /// & '{' ( & '{{{{{' template / tplarg / template )
653663 / & '{' tplarg_or_template
654664 /// & '{' ( tplarg / template )
655665 // Eat three opening brackets as text.
@@ -849,16 +859,18 @@
850860 }
851861
852862 template_param
853 - = name:template_param_name space* "=" space* c:template_param_text? {
854 - //console.log( 'named template_param matched' + pp([name, flatten( c )]) );
855 - if ( c !== '' ) {
856 - return new KV(name, flatten( c ));
 863+ = name:template_param_name space*
 864+ value:( s0:"=" s1:space*
 865+ //& { console.log( 'entering value' ); return true }
 866+ s2:template_param_text { return [s0, s1, s2] } )? {
 867+ //console.log( 'named template_param matched' + pp([name, value ]) );
 868+ if ( value !== '' ) {
 869+ return new KV(name, flatten( value[2] ) || []);
857870 } else {
858 - return new KV(name, []);
 871+ return new KV([], flatten(name));
859872 }
860 - } / c:template_param_text {
861 - return new KV([], flatten( c ) );
862 - }
 873+ }
 874+ // empty parameter
863875 / & [|}] { return new KV([], []); }
864876
865877
@@ -866,8 +878,8 @@
867879 template_param_name
868880 = & { return setFlag( 'equal' ) }
869881 tpt:template_param_text
870 - & { clearFlag( 'equal' ); return true; }
871882 {
 883+ clearFlag( 'equal' );
872884 //console.log( 'template param name matched: ' + pp( tpt ) );
873885 return tpt;
874886 }
@@ -879,6 +891,7 @@
880892 = & { return setFlag('template') }
881893 il:inline {
882894 clearFlag('template');
 895+ //console.log( 'tpt match: ' + pp (il));
883896 return il;
884897 }
885898 / & { return clearFlag('template'); }
@@ -930,12 +943,20 @@
931944
932945 link_text
933946 = & { return setFlag('linkdesc'); }
934 - h:inlineline
 947+ h:inline
 948+ // 'equal' syntaxFlag is set for links in template parameters. Consume the
 949+ // '=' here.
 950+ hs:( '=' inline)?
935951 {
 952+ //console.log('link_text' + pp(h) + pp(hs));
936953 clearFlag('linkdesc');
937 - return h;
 954+ if( hs !== '' ) {
 955+ return h.concat(hs);
 956+ } else {
 957+ return h;
 958+ }
938959 }
939 - / & { clearFlag('linkdesc'); return false }
 960+ / & { return clearFlag('linkdesc'); }
940961
941962 link_end = "]]"
942963

Status & tagging log