prism-excel-formula.js 1.7 KB

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