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 / twr:templateWithOutFirstParameter p:templateParam* { return twr.concat(p) }
27 / t:templateName p:templateParam* { return p.length ? [ t, p ] : [ t ] }
29 templateWithReplacement
30 = t:templateName ":" r:replacement { return [ t, r ] }
32 templateWithOutReplacement
33 = t:templateName ":" p:paramExpression { return [ t, p ] }
35 templateWithOutFirstParameter
36 = t:templateName ":" { return [ t, "" ] }
39 = "|" e:paramExpression* { return e.length > 1 ? [ "CONCAT" ].concat(e) : e[0]; }
42 = tn:[A-Za-z_]+ { return tn.join('').toUpperCase() }
44 /* TODO: Update to reflect separate piped and unpiped handling */
46 = "[[" w:expression "]]" { return [ 'WLINK', w ]; }
49 = "[" url:url whitespace text:expression "]" { return [ 'LINK', url, text ] }
52 = url:[^ ]+ { return url.join(''); }
58 = '$' digits:digits { return [ 'REPLACE', parseInt( digits, 10 ) - 1 ] }
64 = lit:escapedOrRegularLiteral+ { return lit.join(''); }
67 = lit:escapedOrLiteralWithoutBar+ { return lit.join(''); }
69 escapedOrRegularLiteral
73 escapedOrLiteralWithoutBar
75 / regularLiteralWithoutBar
78 = "\\" escaped:. { return escaped; }
83 regularLiteralWithoutBar