|
1 | 1 | start = token* |
2 | 2 |
|
3 | 3 | token |
4 | | - = '{' _ arg:id _ '}' { |
5 | | - return { |
6 | | - type: 'argument', |
7 | | - arg: arg |
8 | | - }; |
9 | | - } |
10 | | - / '{' _ arg:id _ ',' _ 'select' _ ',' _ cases:selectCase+ _ '}' { |
11 | | - return { |
12 | | - type: 'select', |
13 | | - arg: arg, |
14 | | - cases: cases |
15 | | - }; |
16 | | - } |
17 | | - / '{' _ arg:id _ ',' _ type:('plural'/'selectordinal') _ ',' _ offset:offset? cases:pluralCase+ _ '}' { |
18 | | - var ls = ((type === 'selectordinal') ? options.ordinal : options.cardinal) |
19 | | - || ['zero', 'one', 'two', 'few', 'many', 'other']; |
20 | | - if (ls && ls.length) cases.forEach(function(c) { |
21 | | - if (isNaN(c.key) && ls.indexOf(c.key) < 0) throw new Error( |
22 | | - 'Invalid key `' + c.key + '` for argument `' + arg + '`.' + |
23 | | - ' Valid ' + type + ' keys for this locale are `' + ls.join('`, `') + |
24 | | - '`, and explicit keys like `=0`.'); |
25 | | - }); |
26 | | - return { |
27 | | - type: type, |
28 | | - arg: arg, |
29 | | - offset: offset || 0, |
30 | | - cases: cases |
31 | | - }; |
32 | | - } |
33 | | - / '{' _ arg:id _ ',' _ key:id _ params:functionParams* '}' { |
34 | | - return { |
35 | | - type: 'function', |
36 | | - arg: arg, |
37 | | - key: key, |
38 | | - params: params |
39 | | - }; |
40 | | - } |
| 4 | + = argument / select / plural / function |
41 | 5 | / '#' { return { type: 'octothorpe' }; } |
42 | 6 | / str:char+ { return str.join(''); } |
43 | 7 |
|
| 8 | +argument = '{' _ arg:id _ '}' { |
| 9 | + return { |
| 10 | + type: 'argument', |
| 11 | + arg: arg |
| 12 | + }; |
| 13 | + } |
| 14 | + |
| 15 | +select = '{' _ arg:id _ ',' _ 'select' _ ',' _ cases:selectCase+ _ '}' { |
| 16 | + return { |
| 17 | + type: 'select', |
| 18 | + arg: arg, |
| 19 | + cases: cases |
| 20 | + }; |
| 21 | + } |
| 22 | + |
| 23 | +plural = '{' _ arg:id _ ',' _ type:('plural'/'selectordinal') _ ',' _ offset:offset? cases:pluralCase+ _ '}' { |
| 24 | + var ls = ((type === 'selectordinal') ? options.ordinal : options.cardinal) |
| 25 | + || ['zero', 'one', 'two', 'few', 'many', 'other']; |
| 26 | + if (ls && ls.length) cases.forEach(function(c) { |
| 27 | + if (isNaN(c.key) && ls.indexOf(c.key) < 0) throw new Error( |
| 28 | + 'Invalid key `' + c.key + '` for argument `' + arg + '`.' + |
| 29 | + ' Valid ' + type + ' keys for this locale are `' + ls.join('`, `') + |
| 30 | + '`, and explicit keys like `=0`.'); |
| 31 | + }); |
| 32 | + return { |
| 33 | + type: type, |
| 34 | + arg: arg, |
| 35 | + offset: offset || 0, |
| 36 | + cases: cases |
| 37 | + }; |
| 38 | + } |
| 39 | + |
| 40 | +function = '{' _ arg:id _ ',' _ key:id _ params:functionParams* '}' { |
| 41 | + return { |
| 42 | + type: 'function', |
| 43 | + arg: arg, |
| 44 | + key: key, |
| 45 | + params: params |
| 46 | + }; |
| 47 | + } |
| 48 | + |
44 | 49 | id = $([0-9a-zA-Z$_][^ \t\n\r,.+={}]*) |
45 | 50 |
|
46 | 51 | selectCase = _ key:id _ tokens:caseTokens { return { key: key, tokens: tokens }; } |
|
0 commit comments