mode-sql.js 3.1 KB

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