ksql_highlight_rules.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. define(function (require, exports, module) {
  17. "use strict";
  18. var oop = require("../lib/oop");
  19. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  20. var KsqlHighlightRules = function () {
  21. // regexp must not have capturing parentheses. Use (?:) instead.
  22. // regexps are ordered -> the first match is used
  23. var keywords = (
  24. "EMIT|CHANGES|SELECT|FROM|AS|DISTINCT|WHERE|WITHIN|WINDOW|GROUP|BY|HAVING|LIMIT|AT|OR|AND|IN|NOT|EXISTS|BETWEEN|LIKE|IS|INTEGER|DATE|TIME|TIMESTAMP|INTERVAL|YEAR|MONTH|DAY|HOUR|MINUTE|SECOND|MILLISECOND|YEARS|MONTHS|DAYS|HOURS|MINUTES|SECONDS|MILLISECONDS|ZONE|TUMBLING|HOPPING|SIZE|ADVANCE|CASE|WHEN|THEN|ELSE|END|JOIN|FULL|OUTER|INNER|LEFT|RIGHT|ON|PARTITION|STRUCT|WITH|VALUES|CREATE|TABLE|TOPIC|STREAM|STREAMS|INSERT|DELETE|INTO|DESCRIBE|EXTENDED|PRINT|EXPLAIN|ANALYZE|TYPE|TYPES|CAST|SHOW|LIST|TABLES|TOPICS|QUERY|QUERIES|TERMINATE|LOAD|COLUMNS|COLUMN|PARTITIONS|FUNCTIONS|FUNCTION|DROP|TO|RENAME|ARRAY|MAP|SET|RESET|SESSION|SAMPLE|EXPORT|CATALOG|PROPERTIES|BEGINNING|UNSET|RUN|SCRIPT|DECIMAL|KEY|CONNECTOR|CONNECTORS|SINK|SOURCE|IF"
  25. );
  26. var builtinConstants = (
  27. "FALSE|NULL|TRUE"
  28. );
  29. var builtinFunctions = (
  30. "ABS|ARRAYCONTAINS|CEIL|CONCAT|DATETOSTRING|ELT|EXTRACTJSONFIELD|FIELD|FLOOR|GEO_DISTANCE|IFNULL|LCASE|LEN|MASK|MASK_KEEP_LEFT|MASK_KEEP_RIGHT|MASK_LEFT|MASK_RIGHT|RANDOM|ROUND|SPLIT|STRINGTODATE|STRINGTOTIMESTAMP|SUBSTRING|TIMESTAMPTOSTRING|TRIM|UCASE|URL_DECODE_PARAM|URL_ENCODE_PARAM|URL_EXTRACT_FRAGMENT|URL_EXTRACT_HOST|URL_EXTRACT_PARAMETER|URL_EXTRACT_PATH|URL_EXTRACT_PORT|URL_EXTRACT_PROTOCOL|URL_EXTRACT_QUERY|COLLECT_LIST|COLLECT_SET|COUNT|HISTOGRAM|MAX|MIN|SUM|TOPK|TOPKDISTINCT|WindowStart|WindowEnd"
  31. );
  32. var dataTypes = (
  33. "BOOLEAN|INTEGER|INT|BIGINT|DOUBLE|VARCHAR|STRING|ARRAY|MAP|STRUCT"
  34. );
  35. var keywordMapper = this.createKeywordMapper({
  36. "support.function": builtinFunctions,
  37. "keyword": keywords,
  38. "constant.language": builtinConstants,
  39. "storage.type": dataTypes
  40. }, "identifier", true);
  41. this.$rules = {
  42. start: [
  43. {
  44. token : "comment",
  45. regex : "--.*$"
  46. }, {
  47. token : "comment",
  48. start : "/\\*",
  49. end : "\\*/"
  50. }, {
  51. token : "string", // " string
  52. regex : '".*?"'
  53. }, {
  54. token : "string", // ' string
  55. regex : "'.*?'"
  56. }, {
  57. token : "constant.numeric", // float
  58. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  59. }, {
  60. token : keywordMapper,
  61. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  62. }, {
  63. token : "keyword.operator",
  64. regex : "\\+|\\-|\\/|\\/\\/|%|<@>|@>|<@|&|\\^|~|<|>|<=|=>|==|!=|<>|="
  65. }, {
  66. token : "paren.lparen",
  67. regex : "[\\(]"
  68. }, {
  69. token : "paren.rparen",
  70. regex : "[\\)]"
  71. }, {
  72. token : "text",
  73. regex : "\\s+"
  74. }
  75. ]
  76. };
  77. this.normalizeRules();
  78. };
  79. KsqlHighlightRules.metaData = {
  80. fileTypes: ["ksql"],
  81. name: "ksql",
  82. scopeName: "source.ksql"
  83. };
  84. oop.inherits(KsqlHighlightRules, TextHighlightRules);
  85. exports.KsqlHighlightRules = KsqlHighlightRules;
  86. });