http://www.mediawiki.org/wiki/Special:Code/MediaWiki/83625

Revision: 83625
Author:   neilk
Date:     2011-03-10 01:34:39 +0000 (Thu, 10 Mar 2011)
Log Message:
-----------
PEG grammar that mediawiki.language.parser is based on

Added Paths:
-----------
    trunk/extensions/UploadWizard/resources/mediawiki.language.parser.peg

Added: trunk/extensions/UploadWizard/resources/mediawiki.language.parser.peg
===================================================================
--- trunk/extensions/UploadWizard/resources/mediawiki.language.parser.peg       
                        (rev 0)
+++ trunk/extensions/UploadWizard/resources/mediawiki.language.parser.peg       
2011-03-10 01:34:39 UTC (rev 83625)
@@ -0,0 +1,76 @@
+/* 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) }
+  / t:templateName p:templateParam* { return p.length ? [ t, p ] : [ t ] }
+
+templateWithReplacement
+  = t:templateName ":" r:replacement { return [ t, r ] }
+
+templateParam
+  = "|" e:paramExpression* { return e.length > 1 ? [ "CONCAT" ].concat(e) : 
e[0]; }
+
+templateName
+  = tn:[A-Za-z_]+ { return tn.join('').toUpperCase() }
+
+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
+  = [^{}\[\]$\\|]
+


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to