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