Merge "Make last row of new gallery not be huge."
[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 / twr:templateWithOutReplacement 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 templateWithOutReplacement
32 = t:templateName ":" p:paramExpression { return [ t, p ] }
33
34 templateParam
35 = "|" e:paramExpression* { return e.length > 1 ? [ "CONCAT" ].concat(e) : e[0]; }
36
37 templateName
38 = tn:[A-Za-z_]+ { return tn.join('').toUpperCase() }
39
40 /* TODO: Update to reflect separate piped and unpiped handling */
41 link
42 = "[[" w:expression "]]" { return [ 'WLINK', w ]; }
43
44 extlink
45 = "[" url:url whitespace text:expression "]" { return [ 'LINK', url, text ] }
46
47 url
48 = url:[^ ]+ { return url.join(''); }
49
50 whitespace
51 = [ ]+
52
53 replacement
54 = '$' digits:digits { return [ 'REPLACE', parseInt( digits, 10 ) - 1 ] }
55
56 digits
57 = [0-9]+
58
59 literal
60 = lit:escapedOrRegularLiteral+ { return lit.join(''); }
61
62 literalWithoutBar
63 = lit:escapedOrLiteralWithoutBar+ { return lit.join(''); }
64
65 escapedOrRegularLiteral
66 = escapedLiteral
67 / regularLiteral
68
69 escapedOrLiteralWithoutBar
70 = escapedLiteral
71 / regularLiteralWithoutBar
72
73 escapedLiteral
74 = "\\" escaped:. { return escaped; }
75
76 regularLiteral
77 = [^{}\[\]$\\]
78
79 regularLiteralWithoutBar
80 = [^{}\[\]$\\|]
81