r105423 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105422‎ | r105423 | r105424 >
Date:11:51, 7 December 2011
Author:gwicke
Status:deferred
Tags:
Comment:
Fix a bug in doQuotes (bitten by surprising JS sort() behavior), and improve
tag-only-line handling. 180 parser tests now passing.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/pegParser.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/pegParser.pegjs.txt
@@ -199,10 +199,15 @@
200200 var index = bolds[i];
201201 var txt = out[index - 1];
202202 txt.value += "'";
203 - bolds = bolds.slice(0, i)
204 - .concat(bolds.slice(i + 1, bolds.length - i - 1));
 203+ if ( i > 0 ) {
 204+ bolds = bolds.slice(0, i-1)
 205+ .concat(bolds.slice(i + 1, bolds.length - i - 1));
 206+ } else {
 207+ bolds.shift();
 208+ }
 209+
205210 italics.push(index);
206 - italics.sort();
 211+ italics.sort(function(a,b) { return a - b });
207212 };
208213
209214 // convert italics/bolds into tags
@@ -295,12 +300,12 @@
296301 firstspace = j;
297302 } else if (lastchar !== ' ') {
298303 if ( secondtolastchar === ' ' &&
299 - firstsingleletterword === -1) {
300 - firstsingleletterword = j;
301 - } else if ( secondtolastchar &&
302 - secondtolastchar !== ' ') {
303 - firstmultiletterword = j;
304 - }
 304+ firstsingleletterword === -1)
 305+ {
 306+ firstsingleletterword = j;
 307+ } else if ( firstmultiletterword == -1) {
 308+ firstmultiletterword = j;
 309+ }
305310 }
306311 }
307312 }
@@ -475,7 +480,16 @@
476481 space
477482 = s:[ \t]+ { return s.join(''); }
478483
 484+spaceTokenList
 485+ = s:space* {
 486+ if ( s.length ) {
 487+ return [{type: 'TEXT', value: s.join('')}];
 488+ } else {
 489+ return [];
 490+ }
 491+ }
479492
 493+
480494 // Start of line
481495 sol = (newline / & { return pos === 0; } { return true; })
482496 cn:(c:comment n:newline? { return [c, {type: 'TEXT', value: n}] })* {
@@ -537,7 +551,11 @@
538552 / table
539553 / lists
540554 // tag-only lines should not trigger pre
541 - / space* bt:block_tag space* &eolf { return bt }
 555+ / st:spaceTokenList
 556+ bt:(bts:block_tag stl:spaceTokenList { return bts.concat(stl) })+
 557+ &eolf {
 558+ return st.concat(bt);
 559+ }
542560 / pre_indent
543561 / pre
544562
@@ -935,7 +953,7 @@
936954 } else {
937955 res.type = 'TAG';
938956 }
939 - return res;
 957+ return [res];
940958 }
941959
942960 /* Generic XML-like tags
@@ -1127,7 +1145,7 @@
11281146 ("||" / newline "|")
11291147 ! [}+-]
11301148 //& { dp('before attrib, pos=' + pos); return true; }
1131 - a:(as:generic_attribute+ space* "|" !"|" { console.log('bla'); return as } )?
 1149+ a:(as:generic_attribute+ space* "|" !"|" { return as } )?
11321150 //& { dp('past attrib, pos=' + pos); return true; }
11331151 // use inline_breaks to break on tr etc
11341152 td:(!inline_breaks

Follow-up revisions

RevisionCommit summaryAuthorDate
r105424Follow-up to r105423: Fix off-by-one bug.gwicke11:56, 7 December 2011

Status & tagging log