mode-sql.js 2.9 KB

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