https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113818

Revision: 113818
Author:   gwicke
Date:     2012-03-14 16:30:59 +0000 (Wed, 14 Mar 2012)
Log Message:
-----------
Convert syntactical break flags for templates from counters to the stack
variant to fix the precedence for {{!}} (break on these inside table content,
but not in template options within tables).

Modified Paths:
--------------
    trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js
    trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js
    trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt

Modified: 
trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js    
2012-03-14 16:18:27 UTC (rev 113817)
+++ trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js    
2012-03-14 16:30:59 UTC (rev 113818)
@@ -389,12 +389,12 @@
                //              ' vs. ' + JSON.stringify( this.manager.args ) 
); 
                res = this.manager.args[argName];
        } else {
-               var defaultValue = (attributes[1] && ! attributes[1].k.length 
&& attributes[1].v) || false;
                this.manager.env.dp( 'templateArg not found: ', argName,
-                               ' vs. ', defaultValue );
-               if ( defaultValue ) {
-                       res = defaultValue;
+                               ' vs. ' );
+               if ( attributes.length > 1 ) {
+                       res = attributes[1].v;
                } else {
+                       //console.warn('no default for ' + argName + 
JSON.stringify( attributes ));
                        res = [ '{{{' + argName + '}}}' ];
                }
        }

Modified: 
trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js     
2012-03-14 16:18:27 UTC (rev 113817)
+++ trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js     
2012-03-14 16:30:59 UTC (rev 113818)
@@ -114,7 +114,7 @@
                case '|':
                        return counters.pipe ||
                                        counters.template ||
-                               ( counters.table &&
+                               ( stops.onStack('table') &&
                                        ( input[pos + 1].match(/[|}]/) !== null 
||
                                                counters.tableCellArg
                                        ) 
@@ -123,15 +123,14 @@
                        // {{!}} pipe templates..
                        return (
                                                counters.pipe ||
-                                               counters.template || 
-                                               ( counters.table &&
+                                               ( stops.onStack( 'table' ) &&
                                                  ( input.substr(pos, 10) === 
'{{!}}{{!}}' ||
                                                        counters.tableCellArg
                                                  )
                                                )
                                   ) && input.substr( pos, 5 ) === '{{!}}' || 
null;
                case "!":
-                       return counters.table && input[pos + 1] === "!" ||
+                       return stops.onStack( 'table' ) && input[pos + 1] === 
"!" ||
                                null;
                case "}":
                        return counters.template && input[pos + 1] === "}" || 
null;
@@ -140,11 +139,11 @@
                                ! counters.extlink &&
                                ! counters.linkdesc || null;
                case "\r":
-                       return counters.table &&
+                       return stops.onStack( 'table' ) &&
                                input.substr(pos, 4).match(/\r\n?[!|]/) !== 
null ||
                                null;
                case "\n":
-                       return counters.table &&
+                       return stops.onStack( 'table' ) &&
                                input[pos + 1] === '!' ||
                                input[pos + 1] === '|' ||
                                null;

Modified: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt 
2012-03-14 16:18:27 UTC (rev 113817)
+++ trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt 
2012-03-14 16:30:59 UTC (rev 113818)
@@ -721,8 +721,8 @@
 template
   = "{{" (newline / space)* 
     target:template_name
-    params:(( newline / space )* pipe
-                r:( &pipe { return new KV( '', '') } // empty argument
+    params:(( newline / space )* "|"
+                r:( &"|" { return new KV( '', '') } // empty argument
                     / ( newline / space )* p:template_param { return p } 
                   ) { return r } 
             )* 
@@ -743,8 +743,14 @@
 
 tplarg 
   = "{{{" 
-    name:template_param_text?
-    params:( ( space / newline )* '|' ( space / newline )* p:template_param { 
return p })* 
+    name:template_name?
+    params:( ( space / newline )* 
+              '|' ( space / newline )*  
+               r:( 
+                    &'}}' { return new KV( '', '') }
+                    / p:template_param { return p } 
+               ) { return r }
+           )* 
     ( space / newline )* 
     "}}}" {
       name = flatten( name );
@@ -783,6 +789,8 @@
   / & [|}] { return new KV([], []); }
 
 
+template_name = template_param_value
+
 // FIXME: handle template args and templates in key! (or even parser 
functions?)
 template_param_name
   = & { return stops.push( 'equal', true ) }
@@ -796,8 +804,6 @@
   / & { return stops.pop( 'equal' ) }
   //= h:( !"}}" x:([^=|\n]) { return x } )* { return h.join(''); }
 
-template_name = template_param_value
-
 template_param_value
   = & { return stops.push( 'equal', false ) }
     tpt:template_param_text
@@ -809,13 +815,14 @@
   / & { return stops.pop( 'equal' ) }
 
 template_param_text
-  = & { return stops.inc('template') }
-    il:inline {
+  = & { stops.push('table', false ); return stops.inc('template') }
+    il:( inline / nested_block )+ {
+        stops.pop('table');
         stops.dec('template');
         //console.warn( 'tpt match: ' + pp (il));
-        return il;
+        return flatten( il );
     }
-  / & { return stops.dec('template'); }
+  / & { stops.pop('table'); return stops.dec('template'); }
 
 
 // TODO: handle link prefixes as in al[[Razi]]
@@ -1342,14 +1349,15 @@
  *********************************************************************/
 
 table_lines
-  = & { return stops.inc('table'); }
+  = ! inline_breaks
+    & { return stops.push('table', true); }
     tl:table_line 
     tls:( s:sol tl2:table_line { return s.concat(tl2); } )* {
-        stops.dec('table');
+        stops.pop('table');
         //console.warn('table_lines: ' + pp(tl.concat(tls)));
         return tl.concat( tls );
     }
-  / & { return stops.dec('table'); }
+  / & { return stops.pop('table'); }
 
 // This production assumes start-of-line position!
 table_line
@@ -1487,13 +1495,13 @@
 table_start 
   = "{" pipe
     res:(
-        & { stops.inc('table'); return true; }
+        & { stops.push('table', true); return true; }
         ta:generic_attribute* 
         { 
             //dp("table_start " + pp(ta) + ", pos:" + pos);
             return ta;
         }
-        / & { stops.dec('table'); return false; } { return null; }
+        / & { stops.pop('table'); return false; } { return null; }
     ) { return res }
 
 table_caption 
@@ -1534,7 +1542,7 @@
 
 table_data 
   = //& { dp("table_data enter, pos=" + pos + input.substr(pos,10)); return 
true; }
-       n:("||" { return [] } / nt:newlineToken (pipe / !'!') { return nt }) 
+       n:(pipe pipe { return [] } / nt:newlineToken (pipe / !'!') { return nt 
}) 
     ! [}+-]
     //& { dp('before attrib, pos=' + pos); return true; }
     a:(as:generic_attribute+ space* pipe !pipe { return as } )?
@@ -1572,7 +1580,7 @@
 
 table_end 
   = nt:newlineToken? ( pipe "}" / eof ) { 
-         stops.dec('table'); 
+         stops.pop('table'); 
          if(nt) 
                  return nt;
          else


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to