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