UNPKG

1.73 kBJavaScriptView Raw
1Prism.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: /[A-Z]\w*(?=\()/i,
42 alias: 'keyword'
43 },
44 'range': {
45 pattern: /\$?(?:[A-Z]+\$?\d+:\$?[A-Z]+\$?\d+|[A-Z]+:\$?[A-Z]+|\d+:\$?\d+)/i,
46 alias: 'property',
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: /[A-Z]+\d+|\$[A-Za-z]+\$?\d+|[A-Za-z]+\$\d+/,
58 alias: 'property'
59 },
60 'number': /(?:\b\d+(?:\.\d+)?|\B\.\d+)(?:e[+-]?\d+)?\b/i,
61 'boolean': /\b(?:TRUE|FALSE)\b/i,
62 'operator': /[-+*/^%=&,]|<[=>]?|>=?/,
63 'punctuation': /[[\]();{}|]/
64};
65
66Prism.languages['xlsx'] = Prism.languages['xls'] = Prism.languages['excel-formula'];