516ff4bf4f4debec0f60c3e3f3b13c24.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ace.define("ace/mode/csv_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
  2. var oop = require("../lib/oop");
  3. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  4. var CsvHighlightRules = function () {
  5. TextHighlightRules.call(this);
  6. };
  7. oop.inherits(CsvHighlightRules, TextHighlightRules);
  8. exports.CsvHighlightRules = CsvHighlightRules;
  9. });
  10. ace.define("ace/mode/csv",["require","exports","module","ace/lib/oop","ace/mode/text","ace/lib/lang","ace/mode/csv_highlight_rules"], function(require, exports, module){"use strict";
  11. var oop = require("../lib/oop");
  12. var TextMode = require("./text").Mode;
  13. var escapeRegExp = require("../lib/lang").escapeRegExp;
  14. var CsvHighlightRules = require("./csv_highlight_rules").CsvHighlightRules;
  15. var Mode = function (options) {
  16. this.HighlightRules = CsvHighlightRules;
  17. if (!options)
  18. options = {};
  19. var separatorRegex = [options.splitter || ",", options.quote || '"']
  20. .map(escapeRegExp).join("|");
  21. this.$tokenizer = {
  22. getLineTokens: function (line, state, row) {
  23. return tokenizeCsv(line, state, this.options);
  24. },
  25. options: {
  26. quotes: options.quote || '"',
  27. separatorRegex: new RegExp("(" + separatorRegex + ")"),
  28. spliter: options.splitter || ","
  29. },
  30. states: {},
  31. };
  32. this.$highlightRules = new this.HighlightRules();
  33. };
  34. oop.inherits(Mode, TextMode);
  35. (function () {
  36. this.getTokenizer = function () {
  37. return this.$tokenizer;
  38. };
  39. this.$id = "ace/mode/csv";
  40. }).call(Mode.prototype);
  41. exports.Mode = Mode;
  42. var classNames = ["keyword", "text", "string", "string.regex", "variable", "constant.numeric"];
  43. function tokenizeCsv(line, state, options) {
  44. var result = [];
  45. var parts = line.split(options.separatorRegex);
  46. var spliter = options.spliter;
  47. var quote = options.quote || '"';
  48. var stateParts = (state || "start").split("-");
  49. var column = parseInt(stateParts[1]) || 0;
  50. var inString = stateParts[0] == 'string';
  51. var atColumnStart = !inString;
  52. for (var i = 0; i < parts.length; i++) {
  53. var value = parts[i];
  54. if (value) {
  55. var isSeparator = false;
  56. if (value == spliter && !inString) {
  57. column++;
  58. atColumnStart = true;
  59. isSeparator = true;
  60. }
  61. else if (value == quote) {
  62. if (atColumnStart) {
  63. inString = true;
  64. atColumnStart = false;
  65. }
  66. else if (inString) {
  67. if (parts[i + 1] == '' && parts[i + 2] == quote) {
  68. value = quote + quote;
  69. i += 2;
  70. }
  71. else {
  72. inString = false;
  73. }
  74. }
  75. }
  76. else {
  77. atColumnStart = false;
  78. }
  79. result.push({
  80. value: value,
  81. type: classNames[column % classNames.length] + ".csv_" + column + (isSeparator ? ".csv_separator" : "")
  82. });
  83. }
  84. }
  85. return { tokens: result, state: inString ? "string-" + column : "start" };
  86. }
  87. });
  88. ace.define("ace/mode/tsv_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
  89. var oop = require("../lib/oop");
  90. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  91. var TsvHighlightRules = function () {
  92. TextHighlightRules.call(this);
  93. };
  94. oop.inherits(TsvHighlightRules, TextHighlightRules);
  95. exports.TsvHighlightRules = TsvHighlightRules;
  96. });
  97. ace.define("ace/mode/tsv",["require","exports","module","ace/mode/csv","ace/mode/tsv_highlight_rules"], function(require, exports, module){"use strict";
  98. var CSVMode = require("./csv").Mode;
  99. var TsvHighlightRules = require("./tsv_highlight_rules").TsvHighlightRules;
  100. var Mode = function (options) {
  101. var mode = new CSVMode({
  102. splitter: "\t",
  103. quote: '"'
  104. });
  105. mode.HighlightRules = TsvHighlightRules;
  106. mode.$id = "ace/mode/tsv";
  107. return mode;
  108. };
  109. exports.Mode = Mode;
  110. }); (function() {
  111. ace.require(["ace/mode/tsv"], function(m) {
  112. if (typeof module == "object" && typeof exports == "object" && module) {
  113. module.exports = m;
  114. }
  115. });
  116. })();