r83625 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83624‎ | r83625 | r83626 >
Date:01:34, 10 March 2011
Author:neilk
Status:deferred
Tags:
Comment:
PEG grammar that mediawiki.language.parser is based on
Modified paths:
  • /trunk/extensions/UploadWizard/resources/mediawiki.language.parser.peg (added) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/resources/mediawiki.language.parser.peg
@@ -0,0 +1,76 @@
 2+/* PEG grammar for a subset of wikitext, useful in the MediaWiki frontend */
 3+
 4+start
 5+ = e:expression* { return e.length > 1 ? [ "CONCAT" ].concat(e) : e[0]; }
 6+
 7+expression
 8+ = template
 9+ / link
 10+ / extlink
 11+ / replacement
 12+ / literal
 13+
 14+paramExpression
 15+ = template
 16+ / link
 17+ / extlink
 18+ / replacement
 19+ / literalWithoutBar
 20+
 21+template
 22+ = "{{" t:templateContents "}}" { return t; }
 23+
 24+templateContents
 25+ = twr:templateWithReplacement p:templateParam* { return twr.concat(p) }
 26+ / t:templateName p:templateParam* { return p.length ? [ t, p ] : [ t ] }
 27+
 28+templateWithReplacement
 29+ = t:templateName ":" r:replacement { return [ t, r ] }
 30+
 31+templateParam
 32+ = "|" e:paramExpression* { return e.length > 1 ? [ "CONCAT" ].concat(e) : e[0]; }
 33+
 34+templateName
 35+ = tn:[A-Za-z_]+ { return tn.join('').toUpperCase() }
 36+
 37+link
 38+ = "[[" w:expression "]]" { return [ 'WLINK', w ]; }
 39+
 40+extlink
 41+ = "[" url:url whitespace text:expression "]" { return [ 'LINK', url, text ] }
 42+
 43+url
 44+ = url:[^ ]+ { return url.join(''); }
 45+
 46+whitespace
 47+ = [ ]+
 48+
 49+replacement
 50+ = '$' digits:digits { return [ 'REPLACE', parseInt( digits, 10 ) - 1 ] }
 51+
 52+digits
 53+ = [0-9]+
 54+
 55+literal
 56+ = lit:escapedOrRegularLiteral+ { return lit.join(''); }
 57+
 58+literalWithoutBar
 59+ = lit:escapedOrLiteralWithoutBar+ { return lit.join(''); }
 60+
 61+escapedOrRegularLiteral
 62+ = escapedLiteral
 63+ / regularLiteral
 64+
 65+escapedOrLiteralWithoutBar
 66+ = escapedLiteral
 67+ / regularLiteralWithoutBar
 68+
 69+escapedLiteral
 70+ = "\\" escaped:. { return escaped; }
 71+
 72+regularLiteral
 73+ = [^{}\[\]$\\]
 74+
 75+regularLiteralWithoutBar
 76+ = [^{}\[\]$\\|]
 77+

Status & tagging log