r105552 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105551‎ | r105552 | r105553 >
Date:14:34, 8 December 2011
Author:gwicke
Status:deferred
Tags:
Comment:
Clean up newline handling. Emit a NEWLINE token for each
non-{comment,pre,nowiki} newline.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -401,7 +401,8 @@
402402
403403 start
404404 = e:toplevelblock* newline* {
405 - return flatten(e);
 405+ // XXX: move doQuotes out to general token stream transformer
 406+ return doQuotes(flatten(e));
406407 }
407408
408409
@@ -505,6 +506,8 @@
506507 newline
507508 = '\n' / '\r\n'
508509
 510+newlineToken = newline { return [{type: 'NEWLINE'}] }
 511+
509512 eolf = newline / eof
510513
511514 toplevelblock
@@ -517,8 +520,8 @@
518521 }
519522 bs.attribs.push(['data-sourcePos', blockStart + ':' + pos]);
520523 // XXX: only run this for lines that actually need it!
521 - b.push({type: 'NEWLINE'});
522 - b = doQuotes(b);
 524+ //b.push({type: 'NEWLINE'});
 525+ // Move this to a token stream transform!
523526 return b;
524527 }
525528
@@ -1084,7 +1087,7 @@
10851088
10861089 /* Tables */
10871090 table
1088 - = tas:table_start space* c:table_caption? b:table_body? table_end {
 1091+ = tas:table_start space* c:table_caption? b:table_body? te:table_end {
10891092 var res = {type: 'TAG', name: 'table'}
10901093 var body = b !== '' ? b : [];
10911094 dp("body: " + pp(body));
@@ -1096,7 +1099,7 @@
10971100
10981101 if (c != '') {
10991102 var caption = [{type: 'TAG', name: 'caption'}]
1100 - .concat(c, [{type: 'ENDTAG', name: 'caption'}]);
 1103+ .concat(c, [{type: 'ENDTAG', name: 'caption'}], te);
11011104 } else {
11021105 var caption = [];
11031106 }
@@ -1122,9 +1125,9 @@
11231126 = text / ! inline_breaks !newline ![|] c:. { return c }
11241127
11251128 table_caption
1126 - = newline
 1129+ = n:newlineToken
11271130 "|+" c:inline* {
1128 - return c;
 1131+ return n.concat(c);
11291132 }
11301133
11311134 table_body
@@ -1148,15 +1151,15 @@
11491152
11501153 table_row
11511154 = //& { dp("table row enter"); return true; }
1152 - newline
 1155+ n:newlineToken
11531156 "|-" thtd_attribs? space* td:(table_data / table_header)* {
1154 - return [{type: 'TAG', name: 'tr'}]
1155 - .concat(td, [{type: 'ENDTAG', name: 'tr'}]);
 1157+ return n.concat([{type: 'TAG', name: 'tr'}]
 1158+ , td, [{type: 'ENDTAG', name: 'tr'}]);
11561159 }
11571160
11581161 table_data
11591162 = //& { dp("table_data enter, pos=" + pos + input.substr(pos,10)); return true; }
1160 - ("||" / newline "|")
 1163+ n:("||" { return [] } / nt:newlineToken "|" { return nt })
11611164 ! [}+-]
11621165 //& { dp('before attrib, pos=' + pos); return true; }
11631166 a:(as:generic_attribute+ space* "|" !"|" { return as } )?
@@ -1169,19 +1172,19 @@
11701173 a = [];
11711174 }
11721175 //dp("table data result: " + pp(td) + ", attribts: " + pp(a));
1173 - return [{ type: 'TAG', name: 'td', attribs: a}]
1174 - .concat(td, [{type: 'ENDTAG', name: 'td'}]);
 1176+ return n.concat( [{ type: 'TAG', name: 'td', attribs: a}]
 1177+ , td, [{type: 'ENDTAG', name: 'td'}] );
11751178 }
11761179
11771180 table_header
1178 - = ("!!" / newline "!")
 1181+ = n:("!!" { return [] } / nl:newlineToken "!" { return nl })
11791182 a:(as:generic_attribute+ "!" !"!" { return as } )?
11801183 c:inline {
11811184 if ( a == '' ) {
11821185 a = [];
11831186 }
1184 - return [{type: 'TAG', name: 'th', attribs: a}]
1185 - .concat(c, [{type: 'ENDTAG', name: 'th'}]);
 1187+ return n.concat( [{type: 'TAG', name: 'th', attribs: a}]
 1188+ , c, [{type: 'ENDTAG', name: 'th'}]);
11861189 }
11871190
11881191 thtd_attribs
@@ -1192,8 +1195,13 @@
11931196
11941197
11951198 table_end
1196 - = newline? "|}" { clearFlag('table'); }
1197 - / newline? eof
 1199+ = nt:newlineToken? ( "|}" / eof ) {
 1200+ clearFlag('table');
 1201+ if(nt)
 1202+ return nt;
 1203+ else
 1204+ return [];
 1205+ }
11981206
11991207
12001208 /* Tabs do not mix well with the hybrid production syntax */

Status & tagging log