diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2014-12-27 15:41:37 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2014-12-31 11:43:28 +0100 |
commit | c1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch) | |
tree | 2b38796e738dd74cb42ecd9bfd151803108386bc /resources/src/mediawiki/mediawiki.jqueryMsg.peg | |
parent | b88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff) |
Update to MediaWiki 1.24.1
Diffstat (limited to 'resources/src/mediawiki/mediawiki.jqueryMsg.peg')
-rw-r--r-- | resources/src/mediawiki/mediawiki.jqueryMsg.peg | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/resources/src/mediawiki/mediawiki.jqueryMsg.peg b/resources/src/mediawiki/mediawiki.jqueryMsg.peg new file mode 100644 index 00000000..716c3261 --- /dev/null +++ b/resources/src/mediawiki/mediawiki.jqueryMsg.peg @@ -0,0 +1,85 @@ +/* PEG grammar for a subset of wikitext, useful in the MediaWiki frontend */ + +start + = e:expression* { return e.length > 1 ? [ "CONCAT" ].concat(e) : e[0]; } + +expression + = template + / link + / extlink + / replacement + / literal + +paramExpression + = template + / link + / extlink + / replacement + / literalWithoutBar + +template + = "{{" t:templateContents "}}" { return t; } + +templateContents + = twr:templateWithReplacement p:templateParam* { return twr.concat(p) } + / twr:templateWithOutReplacement p:templateParam* { return twr.concat(p) } + / twr:templateWithOutFirstParameter p:templateParam* { return twr.concat(p) } + / t:templateName p:templateParam* { return p.length ? [ t, p ] : [ t ] } + +templateWithReplacement + = t:templateName ":" r:replacement { return [ t, r ] } + +templateWithOutReplacement + = t:templateName ":" p:paramExpression { return [ t, p ] } + +templateWithOutFirstParameter + = t:templateName ":" { return [ t, "" ] } + +templateParam + = "|" e:paramExpression* { return e.length > 1 ? [ "CONCAT" ].concat(e) : e[0]; } + +templateName + = tn:[A-Za-z_]+ { return tn.join('').toUpperCase() } + +/* TODO: Update to reflect separate piped and unpiped handling */ +link + = "[[" w:expression "]]" { return [ 'WLINK', w ]; } + +extlink + = "[" url:url whitespace text:expression "]" { return [ 'LINK', url, text ] } + +url + = url:[^ ]+ { return url.join(''); } + +whitespace + = [ ]+ + +replacement + = '$' digits:digits { return [ 'REPLACE', parseInt( digits, 10 ) - 1 ] } + +digits + = [0-9]+ + +literal + = lit:escapedOrRegularLiteral+ { return lit.join(''); } + +literalWithoutBar + = lit:escapedOrLiteralWithoutBar+ { return lit.join(''); } + +escapedOrRegularLiteral + = escapedLiteral + / regularLiteral + +escapedOrLiteralWithoutBar + = escapedLiteral + / regularLiteralWithoutBar + +escapedLiteral + = "\\" escaped:. { return escaped; } + +regularLiteral + = [^{}\[\]$\\] + +regularLiteralWithoutBar + = [^{}\[\]$\\|] + |