Cscott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/50259
Change subject: Parse "options" sections in parserTests.txt test cases.
......................................................................
Parse "options" sections in parserTests.txt test cases.
Change-Id: I5ff431491575af9975101165c29e58550a1b6439
---
M js/tests/parserTests.js
M js/tests/parserTests.pegjs
2 files changed, 58 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/59/50259/1
diff --git a/js/tests/parserTests.js b/js/tests/parserTests.js
index ce15b86..08905d5 100644
--- a/js/tests/parserTests.js
+++ b/js/tests/parserTests.js
@@ -91,6 +91,14 @@
this.stats.modes = newModes;
}
+var prettyPrintIOptions = function(iopts) {
+ if (!iopts) { return ''; }
+ return Object.keys(iopts).map(function(k) {
+ if (iopts[k]==='') { return k; }
+ return k+'='+iopts[k];
+ }).join(' ');
+};
+
/**
* Get the options from the command line.
*/
@@ -697,7 +705,7 @@
if ( options ) {
console.log( 'OPTIONS'.cyan + ':' );
- console.log( iopts + '\n' );
+ console.log( prettyPrintIOptions(iopts) + '\n' );
}
console.log( 'INPUT'.cyan + ':' );
diff --git a/js/tests/parserTests.pegjs b/js/tests/parserTests.pegjs
index 7e33d39..ad644c4 100644
--- a/js/tests/parserTests.pegjs
+++ b/js/tests/parserTests.pegjs
@@ -100,7 +100,7 @@
test =
start_test
title:text
- sections:section*
+ sections:(section / option_section)*
end_test
{
var test = {
@@ -115,7 +115,7 @@
}
section =
- "!!" ws? (!"end") name:(c:[a-zA-Z0-9]+ { return c.join(''); }) rest_of_line
+ "!!" ws? (!"end") (!"options") name:(c:[a-zA-Z0-9]+ { return c.join('');
}) rest_of_line
text:text
{
return {
@@ -124,6 +124,53 @@
};
}
+option_section =
+ "!!" ws? "options" ws? eol
+ opts:option_list?
+{
+ var o = {};
+ if (opts && opts.length) {
+ for (var i = 0; i < opts.length; i++) {
+ o[opts[i].k] = opts[i].v || '';
+ }
+ }
+ return {
+ name: "options",
+ text: o
+ };
+}
+
+option_list = o:an_option [ \t\n]+ rest:option_list?
+{
+ var result = [ o ];
+ if (rest && rest.length) {
+ result.push.apply(result, rest);
+ }
+ return result;
+}
+
+an_option = simple_option / prefix_option
+
+simple_option = k:("pst" / "PST" / "msg" / "cat" / "ill" / "subpage" /
+ "noxml" / "disabled" / "showtitle" / "comment" / "local" /
+ "rawhtml" / "preload" )
+{
+ return {k:k.toLowerCase()};
+}
+prefix_option = title_option / nospace_prefix_option
+
+nospace_prefix_option = k:(c:[^ \t\n=]+ { return c.join(''); }) ws? "=" ws?
+ v:(c:[^ \t\n]+ { return c.join(''); })
+{
+ return {k:k, v:v};
+}
+
+title_option = k:"title" ws? "=" ws?
+ v:("[[" (c:[^\]]+ { return c.join(''); }) "]]")
+{
+ return {k:k, v:"[["+v+"]]"};
+}
+
/* the : is for a stray one, not sure it should be there */
start_test =
--
To view, visit https://gerrit.wikimedia.org/r/50259
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5ff431491575af9975101165c29e58550a1b6439
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits