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 / twr:templateWithOutReplacement p:templateParam* { return twr.concat(p) }
26 / t:templateName p:templateParam* { return p.length ? [ t, p ] : [ t ] }
28 templateWithReplacement
29 = t:templateName ":" r:replacement { return [ t, r ] }
31 templateWithOutReplacement
32 = t:templateName ":" p:paramExpression { return [ t, p ] }
35 = "|" e:paramExpression* { return e.length > 1 ? [ "CONCAT" ].concat(e) : e[0]; }
38 = tn:[A-Za-z_]+ { return tn.join('').toUpperCase() }
41 = "[[" w:expression "]]" { return [ 'WLINK', w ]; }
44 = "[" url:url whitespace text:expression "]" { return [ 'LINK', url, text ] }
47 = url:[^ ]+ { return url.join(''); }
53 = '$' digits:digits { return [ 'REPLACE', parseInt( digits, 10 ) - 1 ] }
59 = lit:escapedOrRegularLiteral+ { return lit.join(''); }
62 = lit:escapedOrLiteralWithoutBar+ { return lit.join(''); }
64 escapedOrRegularLiteral
68 escapedOrLiteralWithoutBar
70 / regularLiteralWithoutBar
73 = "\\" escaped:. { return escaped; }
78 regularLiteralWithoutBar