hplsql_highlight_rules.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 HplsqlHighlightRules = function () {
  21. // regexp must not have capturing parentheses. Use (?:) instead.
  22. // regexps are ordered -> the first match is used
  23. var keywords =
  24. 'ALLOCATE|ASSOCIATE|BREAK|CALL|CLOSE|CMP|CONDITION|COPY|CREATE|CURSOR|DATABASE|DECLARE|DESCRIBE|DIAGNOSTICS|'+
  25. 'DIRECTORY|DROP|EXEC|EXECUTE|EXIT|FETCH|FOR|FROM|FTP|FUNCTION|GET|HANDLER|HIVE|HOST|IF|IMMEDIATE|INCLUDE|'+
  26. 'INSERT|INTO|LEAVE|LOCAL|LOCATOR|LOOP|MAP|NULL|OBJECT|OPEN|PACKAGE|PRINT|PROCEDURE|RESIGNAL|RESULT|'+
  27. 'RETURN|SELECT|SET|SIGNAL|SUMMARY|TABLE|TEMPORARY|TRUNCATE|UPDATE|USE|VALUES|VOLATILE|WHEN|WHILE|.IF|.QUIT';
  28. var builtinConstants = 'FALSE|NULL|TRUE';
  29. var builtinFunctions =
  30. 'CAST|CHAR|COALESCE|CONCAT|CURRENT_DATE|CURRENT_TIMESTAMP|CURRENT_USER|DATE|DBMS_OUTPUT|PUT_LINE|DECODE|'+
  31. 'FROM_UNIXTIME|INSTR|LEN|LENGTH|LOWER|MAX_PART_DATE|MAX_PART_INT|MAX_PART_STRING|MIN_PART_DATE|MIN_PART_INT|'+
  32. 'MIN_PART_STRING|NOW|NVL|NVL2|PART_COUNT|PART_COUNT_BY|PART_LOC|REPLACE|SUBSTR|SUBSTRING|SYSDATE|TIMESTAMP_ISO|'+
  33. 'TO_CHAR|TO_TIMESTAMP|TRIM|UNIX_TIMESTAMP|UPPER';
  34. var dataTypes =
  35. 'BIGINT|BINARY_DOUBLE|BINARY_FLOAT|BINARY_INTEGER|BIT|BOOL|BOOLEAN|CHAR|CHARACTER|DATE|DATETIME|DECIMAL|DOUBLE|'+
  36. 'FLOAT|INT|INT2|INT8|INTEGER|NCHAR|NUMBER|NUMERIC|NVARCHAR|PLS_INTEGER|PRECISION|REAL|RECORD|SIMPLE_DOUBLE|'+
  37. 'SIMPLE_FLOAT|SIMPLE_INTEGER|SMALLINT|SYS_REFCURSOR|TIMESTAMP|TINYINT|VARCHAR|VARCHAR2|UTL_FILE|FILE_TYPE';
  38. var keywordMapper = this.createKeywordMapper({
  39. "support.function": builtinFunctions,
  40. "keyword": keywords,
  41. "constant.language": builtinConstants,
  42. "storage.type": dataTypes
  43. }, "identifier", true);
  44. this.$rules = {
  45. start: [
  46. {
  47. token : "comment",
  48. regex : "--.*$"
  49. }, {
  50. token : "comment",
  51. start : "/\\*",
  52. end : "\\*/"
  53. }, {
  54. token : "string", // " string
  55. regex : '".*?"'
  56. }, {
  57. token : "string", // ' string
  58. regex : "'.*?'"
  59. }, {
  60. token : "constant.numeric", // float
  61. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  62. }, {
  63. token : keywordMapper,
  64. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  65. }, {
  66. token : "keyword.operator",
  67. regex : "\\+|\\-|\\/|\\/\\/|%|<@>|@>|<@|&|\\^|~|<|>|<=|=>|==|!=|<>|="
  68. }, {
  69. token : "paren.lparen",
  70. regex : "[\\(]"
  71. }, {
  72. token : "paren.rparen",
  73. regex : "[\\)]"
  74. }, {
  75. token : "text",
  76. regex : "\\s+"
  77. }
  78. ]
  79. };
  80. this.normalizeRules();
  81. };
  82. HplsqlHighlightRules.metaData = {
  83. fileTypes: ["hplsql"],
  84. name: "Hplsql",
  85. scopeName: "source.hplsql"
  86. };
  87. oop.inherits(HplsqlHighlightRules, TextHighlightRules);
  88. exports.HplsqlHighlightRules = HplsqlHighlightRules;
  89. });