mode-sql.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // jshint ignore: start
  2. // jscs: disable
  3. ace.define("ace/mode/sql_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  4. "use strict";
  5. var oop = require("../lib/oop");
  6. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  7. var SqlHighlightRules = function() {
  8. var keywords = (
  9. "select|insert|update|delete|from|where|and|or|group|by|order|limit|offset|having|as|case|" +
  10. "when|else|end|type|left|right|join|on|outer|desc|asc|union|create|table|primary|key|if|" +
  11. "foreign|not|references|default|null|inner|cross|natural|database|drop|grant"
  12. );
  13. var builtinConstants = (
  14. "true|false"
  15. );
  16. var builtinFunctions = (
  17. "avg|count|first|last|max|min|sum|ucase|lcase|mid|len|round|rank|now|format|" +
  18. "coalesce|ifnull|isnull|nvl"
  19. );
  20. var dataTypes = (
  21. "int|numeric|decimal|date|varchar|char|bigint|float|double|bit|binary|text|set|timestamp|" +
  22. "money|real|number|integer"
  23. );
  24. var keywordMapper = this.createKeywordMapper({
  25. "support.function": builtinFunctions,
  26. "keyword": keywords,
  27. "constant.language": builtinConstants,
  28. "storage.type": dataTypes
  29. }, "identifier", true);
  30. this.$rules = {
  31. "start" : [ {
  32. token : "comment",
  33. regex : "--.*$"
  34. }, {
  35. token : "comment",
  36. start : "/\\*",
  37. end : "\\*/"
  38. }, {
  39. token : "string", // " string
  40. regex : '".*?"'
  41. }, {
  42. token : "string", // ' string
  43. regex : "'.*?'"
  44. }, {
  45. token : "string", // ` string (apache drill)
  46. regex : "`.*?`"
  47. }, {
  48. token : "constant.numeric", // float
  49. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  50. }, {
  51. token : keywordMapper,
  52. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  53. }, {
  54. token : "keyword.operator",
  55. regex : "\\+|\\-|\\/|\\/\\/|%|<@>|@>|<@|&|\\^|~|<|>|<=|=>|==|!=|<>|="
  56. }, {
  57. token : "paren.lparen",
  58. regex : "[\\(]"
  59. }, {
  60. token : "paren.rparen",
  61. regex : "[\\)]"
  62. }, {
  63. token : "text",
  64. regex : "\\s+"
  65. } ]
  66. };
  67. this.normalizeRules();
  68. };
  69. oop.inherits(SqlHighlightRules, TextHighlightRules);
  70. exports.SqlHighlightRules = SqlHighlightRules;
  71. });
  72. ace.define("ace/mode/sql",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/sql_highlight_rules"], function(require, exports, module) {
  73. "use strict";
  74. var oop = require("../lib/oop");
  75. var TextMode = require("./text").Mode;
  76. var SqlHighlightRules = require("./sql_highlight_rules").SqlHighlightRules;
  77. var Mode = function() {
  78. this.HighlightRules = SqlHighlightRules;
  79. this.$behaviour = this.$defaultBehaviour;
  80. };
  81. oop.inherits(Mode, TextMode);
  82. (function() {
  83. this.lineCommentStart = "--";
  84. this.$id = "ace/mode/sql";
  85. }).call(Mode.prototype);
  86. exports.Mode = Mode;
  87. });