1 /* PEG grammar for a subset of wikitext, useful in the MediaWiki frontend */
4 = e:expression* { return e.length > 1 ? [ "CONCAT" ].concat(e) : e[0]; }
21 = "{{" t:templateContents "}}" { return t; }
24 = twr:templateWithReplacement p:templateParam* { return twr.concat(p) }
25 / t:templateName p:templateParam* { return p.length ? [ t, p ] : [ t ] }
27 templateWithReplacement
28 = t:templateName ":" r:replacement { return [ t, r ] }
31 = "|" e:paramExpression* { return e.length > 1 ? [ "CONCAT" ].concat(e) : e[0]; }
34 = tn:[A-Za-z_]+ { return tn.join('').toUpperCase() }
37 = "[[" w:expression "]]" { return [ 'WLINK', w ]; }
40 = "[" url:url whitespace text:expression "]" { return [ 'LINK', url, text ] }
43 = url:[^ ]+ { return url.join(''); }
49 = '$' digits:digits { return [ 'REPLACE', parseInt( digits, 10 ) - 1 ] }
55 = lit:escapedOrRegularLiteral+ { return lit.join(''); }
58 = lit:escapedOrLiteralWithoutBar+ { return lit.join(''); }
60 escapedOrRegularLiteral
64 escapedOrLiteralWithoutBar
66 / regularLiteralWithoutBar
69 = "\\" escaped:. { return escaped; }
74 regularLiteralWithoutBar