1 | Prism.languages['excel-formula'] = {
|
---|
2 | 'comment': {
|
---|
3 | pattern: /(\bN\(\s*)"(?:[^"]|"")*"(?=\s*\))/i,
|
---|
4 | lookbehind: true,
|
---|
5 | greedy: true
|
---|
6 | },
|
---|
7 | 'string': {
|
---|
8 | pattern: /"(?:[^"]|"")*"(?!")/,
|
---|
9 | greedy: true
|
---|
10 | },
|
---|
11 | 'reference': {
|
---|
12 | // https://www.ablebits.com/office-addins-blog/2015/12/08/excel-reference-another-sheet-workbook/
|
---|
13 |
|
---|
14 | // Sales!B2
|
---|
15 | // 'Winter sales'!B2
|
---|
16 | // [Sales.xlsx]Jan!B2:B5
|
---|
17 | // D:\Reports\[Sales.xlsx]Jan!B2:B5
|
---|
18 | // '[Sales.xlsx]Jan sales'!B2:B5
|
---|
19 | // 'D:\Reports\[Sales.xlsx]Jan sales'!B2:B5
|
---|
20 |
|
---|
21 | pattern: /(?:'[^']*'|(?:[^\s()[\]{}<>*?"';,$&]*\[[^^\s()[\]{}<>*?"']+\])?\w+)!/,
|
---|
22 | greedy: true,
|
---|
23 | alias: 'string',
|
---|
24 | inside: {
|
---|
25 | 'operator': /!$/,
|
---|
26 | 'punctuation': /'/,
|
---|
27 | 'sheet': {
|
---|
28 | pattern: /[^[\]]+$/,
|
---|
29 | alias: 'function'
|
---|
30 | },
|
---|
31 | 'file': {
|
---|
32 | pattern: /\[[^[\]]+\]$/,
|
---|
33 | inside: {
|
---|
34 | 'punctuation': /[[\]]/
|
---|
35 | }
|
---|
36 | },
|
---|
37 | 'path': /[\s\S]+/
|
---|
38 | }
|
---|
39 | },
|
---|
40 | 'function-name': {
|
---|
41 | pattern: /\b[A-Z]\w*(?=\()/i,
|
---|
42 | alias: 'builtin'
|
---|
43 | },
|
---|
44 | 'range': {
|
---|
45 | pattern: /\$?\b(?:[A-Z]+\$?\d+:\$?[A-Z]+\$?\d+|[A-Z]+:\$?[A-Z]+|\d+:\$?\d+)\b/i,
|
---|
46 | alias: 'selector',
|
---|
47 | inside: {
|
---|
48 | 'operator': /:/,
|
---|
49 | 'cell': /\$?[A-Z]+\$?\d+/i,
|
---|
50 | 'column': /\$?[A-Z]+/i,
|
---|
51 | 'row': /\$?\d+/
|
---|
52 | }
|
---|
53 | },
|
---|
54 | 'cell': {
|
---|
55 | // Excel is case insensitive, so the string "foo1" could be either a variable or a cell.
|
---|
56 | // To combat this, we match cells case insensitive, if the contain at least one "$", and case sensitive otherwise.
|
---|
57 | pattern: /\b[A-Z]+\d+\b|\$[A-Za-z]+\$?\d+\b|\b[A-Za-z]+\$\d+\b/,
|
---|
58 | alias: 'selector'
|
---|
59 | },
|
---|
60 | 'number': /(?:\b\d+(?:\.\d+)?|\B\.\d+)(?:e[+-]?\d+)?\b/i,
|
---|
61 | 'boolean': /\b(?:FALSE|TRUE)\b/i,
|
---|
62 | 'operator': /[-+*/^%=&,]|<[=>]?|>=?/,
|
---|
63 | 'punctuation': /[[\]();{}|]/
|
---|
64 | };
|
---|
65 |
|
---|
66 | Prism.languages['xlsx'] = Prism.languages['xls'] = Prism.languages['excel-formula'];
|
---|