Cscott has uploaded a new change for review. https://gerrit.wikimedia.org/r/50618
Change subject: Parse "options" sections in parserTests.txt test cases (take 2). ...................................................................... Parse "options" sections in parserTests.txt test cases (take 2). Improvement to already-merged 0110b0b46b3d150032fdcebf8a12fe2c776522d8. This grammar matches more closely the grammar found in the PHP test parser at tests/parser/parserTest.inc:parseOptions() and handles value lists and the newly-added "parsoid" simple option. (The latter by replacing the hard-coded list of simple options with a more flexible parser.) Change-Id: Ic449411afd8f5906dd140b0020b52b49fe1b44c7 --- M js/tests/parserTests.js M js/tests/parserTests.pegjs 2 files changed, 54 insertions(+), 17 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid refs/changes/18/50618/1 diff --git a/js/tests/parserTests.js b/js/tests/parserTests.js index ce4b496..7d3b5d1 100644 --- a/js/tests/parserTests.js +++ b/js/tests/parserTests.js @@ -93,9 +93,20 @@ var prettyPrintIOptions = function(iopts) { if (!iopts) { return ''; } + var ppValue = function(v) { + if ($.isArray(v)) { + return v.map(ppValue).join(','); + } + if (/^\[\[[^\]]*\]\]$/.test(v) || + /^[-\w]+$/.test(v)) { + return v; + } + console.assert(v.indexOf('"') < 0); + return '"'+v+'"'; + }; return Object.keys(iopts).map(function(k) { if (iopts[k]==='') { return k; } - return k+'='+iopts[k]; + return k+'='+ppValue(iopts[k]); }).join(' '); }; diff --git a/js/tests/parserTests.pegjs b/js/tests/parserTests.pegjs index bcf8f08..1135217 100644 --- a/js/tests/parserTests.pegjs +++ b/js/tests/parserTests.pegjs @@ -149,26 +149,52 @@ return result; } -an_option = simple_option / prefix_option - -simple_option = k:("pst"i / "msg"i / "cat"i / "ill"i / "subpage"i / - "noxml"i / "disabled"i / "showtitle"i / "comment"i / - "local"i / "rawhtml"i / "preload"i ) +// from PHP parser in tests/parser/parserTest.inc:parseOptions() +// foo +// foo=bar +// foo="bar baz" +// foo=[[bar baz]] +// foo=bar,"baz quux",[[bat]] +an_option = k:option_name v:option_value? { - 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}; + return {k:k.toLowerCase(), v:(v||'')}; } -title_option = k:"title" ws? "=" ws? - v:("[[" (c:[^\]]+ { return c.join(''); }) "]]") +option_name = c:[^ \t\n=!]+ { - return {k:k, v:"[["+v+"]]"}; + return c.join(''); +} + +option_value = ws? "=" ws? ovl:option_value_list +{ + return (ovl.length===1) ? ovl[0] : ovl; +} + +option_value_list = v:an_option_value + rest:( ws? "," ws? ovl:option_value_list {return ovl; })? +{ + var result = [ v ]; + if (rest && rest.length) { + result.push.apply(result, rest); + } + return result; +} + +an_option_value = link_target_value / quoted_value / plain_value + +link_target_value = v:("[[" (c:[^\]]* { return c.join(''); }) "]]") +{ + return v.join(''); +} + +quoted_value = [\"] v:[^\"]* [\"] +{ + return v.join(''); +} + +plain_value = v:[^ \t\n\"\'\[\]=,!]+ +{ + return v.join(''); } /* the : is for a stray one, not sure it should be there */ -- To view, visit https://gerrit.wikimedia.org/r/50618 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic449411afd8f5906dd140b0020b52b49fe1b44c7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Parsoid Gerrit-Branch: master Gerrit-Owner: Cscott <wikime...@cscott.net> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits