kusto.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. export const FUNCTIONS = [
  2. { text: 'countof', display: 'countof()', hint: '' },
  3. { text: 'bin', display: 'bin()', hint: '' },
  4. { text: 'extentid', display: 'extentid()', hint: '' },
  5. { text: 'extract', display: 'extract()', hint: '' },
  6. { text: 'extractjson', display: 'extractjson()', hint: '' },
  7. { text: 'floor', display: 'floor()', hint: '' },
  8. { text: 'iif', display: 'iif()', hint: '' },
  9. { text: 'isnull', display: 'isnull()', hint: '' },
  10. { text: 'isnotnull', display: 'isnotnull()', hint: '' },
  11. { text: 'notnull', display: 'notnull()', hint: '' },
  12. { text: 'isempty', display: 'isempty()', hint: '' },
  13. { text: 'isnotempty', display: 'isnotempty()', hint: '' },
  14. { text: 'notempty', display: 'notempty()', hint: '' },
  15. { text: 'now', display: 'now()', hint: '' },
  16. { text: 're2', display: 're2()', hint: '' },
  17. { text: 'strcat', display: 'strcat()', hint: '' },
  18. { text: 'strlen', display: 'strlen()', hint: '' },
  19. { text: 'toupper', display: 'toupper()', hint: '' },
  20. { text: 'tostring', display: 'tostring()', hint: '' },
  21. { text: 'count', display: 'count()', hint: '' },
  22. { text: 'cnt', display: 'cnt()', hint: '' },
  23. { text: 'sum', display: 'sum()', hint: '' },
  24. { text: 'min', display: 'min()', hint: '' },
  25. { text: 'max', display: 'max()', hint: '' },
  26. { text: 'avg', display: 'avg()', hint: '' },
  27. ];
  28. export const KEYWORDS = [
  29. 'by', 'on', 'contains', 'notcontains', 'containscs', 'notcontainscs', 'startswith', 'has', 'matches', 'regex', 'true',
  30. 'false', 'and', 'or', 'typeof', 'int', 'string', 'date', 'datetime', 'time', 'long', 'real', '​boolean', 'bool',
  31. // add some more keywords
  32. 'where', 'order'
  33. ];
  34. // Kusto operators
  35. // export const OPERATORS = ['+', '-', '*', '/', '>', '<', '==', '<>', '<=', '>=', '~', '!~'];
  36. export const DURATION = [
  37. 'SECONDS',
  38. 'MINUTES',
  39. 'HOURS',
  40. 'DAYS',
  41. 'WEEKS',
  42. 'MONTHS',
  43. 'YEARS'
  44. ];
  45. const tokenizer = {
  46. comment: {
  47. pattern: /(^|[^\\:])\/\/.*/,
  48. lookbehind: true,
  49. greedy: true,
  50. },
  51. 'function-context': {
  52. pattern: /[a-z0-9_]+\([^)]*\)?/i,
  53. inside: {},
  54. },
  55. duration: {
  56. pattern: new RegExp(`${DURATION.join('?|')}?`, 'i'),
  57. alias: 'number',
  58. },
  59. builtin: new RegExp(`\\b(?:${FUNCTIONS.map(f => f.text).join('|')})(?=\\s*\\()`, 'i'),
  60. string: {
  61. pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  62. greedy: true,
  63. },
  64. keyword: new RegExp(`\\b(?:${KEYWORDS.join('|')}|\\*)\\b`, 'i'),
  65. boolean: /\b(?:true|false)\b/,
  66. number: /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i,
  67. operator: /-|\+|\*|\/|>|<|==|<=?|>=?|<>|!~|~|=|\|/,
  68. punctuation: /[{};(),.:]/,
  69. variable: /(\[\[(.+?)\]\])|(\$(.+?))\b/
  70. };
  71. tokenizer['function-context'].inside = {
  72. argument: {
  73. pattern: /[a-z0-9_]+(?=:)/i,
  74. alias: 'symbol',
  75. },
  76. duration: tokenizer.duration,
  77. number: tokenizer.number,
  78. builtin: tokenizer.builtin,
  79. string: tokenizer.string,
  80. variable: tokenizer.variable,
  81. };
  82. export default tokenizer;