mode-toml.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. ace.define("ace/mode/toml_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 TomlHighlightRules = function() {
  6. var keywordMapper = this.createKeywordMapper({
  7. "constant.language.boolean": "true|false"
  8. }, "identifier");
  9. var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*\\b";
  10. this.$rules = {
  11. "start": [
  12. {
  13. token: "comment.toml",
  14. regex: /#.*$/
  15. },
  16. {
  17. token : "string",
  18. regex : '"(?=.)',
  19. next : "qqstring"
  20. },
  21. {
  22. token: ["variable.keygroup.toml"],
  23. regex: "(?:^\\s*)(\\[\\[([^\\]]+)\\]\\])"
  24. },
  25. {
  26. token: ["variable.keygroup.toml"],
  27. regex: "(?:^\\s*)(\\[([^\\]]+)\\])"
  28. },
  29. {
  30. token : keywordMapper,
  31. regex : identifierRe
  32. },
  33. {
  34. token : "support.date.toml",
  35. regex: "\\d{4}-\\d{2}-\\d{2}(T)\\d{2}:\\d{2}:\\d{2}(Z)"
  36. },
  37. {
  38. token: "constant.numeric.toml",
  39. regex: "-?\\d+(\\.?\\d+)?"
  40. }
  41. ],
  42. "qqstring" : [
  43. {
  44. token : "string",
  45. regex : "\\\\$",
  46. next : "qqstring"
  47. },
  48. {
  49. token : "constant.language.escape",
  50. regex : '\\\\[0tnr"\\\\]'
  51. },
  52. {
  53. token : "string",
  54. regex : '"|$',
  55. next : "start"
  56. },
  57. {
  58. defaultToken: "string"
  59. }
  60. ]
  61. };
  62. };
  63. oop.inherits(TomlHighlightRules, TextHighlightRules);
  64. exports.TomlHighlightRules = TomlHighlightRules;
  65. });
  66. ace.define("ace/mode/folding/ini",[], function(require, exports, module) {
  67. "use strict";
  68. var oop = require("../../lib/oop");
  69. var Range = require("../../range").Range;
  70. var BaseFoldMode = require("./fold_mode").FoldMode;
  71. var FoldMode = exports.FoldMode = function() {
  72. };
  73. oop.inherits(FoldMode, BaseFoldMode);
  74. (function() {
  75. this.foldingStartMarker = /^\s*\[([^\])]*)]\s*(?:$|[;#])/;
  76. this.getFoldWidgetRange = function(session, foldStyle, row) {
  77. var re = this.foldingStartMarker;
  78. var line = session.getLine(row);
  79. var m = line.match(re);
  80. if (!m) return;
  81. var startName = m[1] + ".";
  82. var startColumn = line.length;
  83. var maxRow = session.getLength();
  84. var startRow = row;
  85. var endRow = row;
  86. while (++row < maxRow) {
  87. line = session.getLine(row);
  88. if (/^\s*$/.test(line))
  89. continue;
  90. m = line.match(re);
  91. if (m && m[1].lastIndexOf(startName, 0) !== 0)
  92. break;
  93. endRow = row;
  94. }
  95. if (endRow > startRow) {
  96. var endColumn = session.getLine(endRow).length;
  97. return new Range(startRow, startColumn, endRow, endColumn);
  98. }
  99. };
  100. }).call(FoldMode.prototype);
  101. });
  102. ace.define("ace/mode/toml",[], function(require, exports, module) {
  103. "use strict";
  104. var oop = require("../lib/oop");
  105. var TextMode = require("./text").Mode;
  106. var TomlHighlightRules = require("./toml_highlight_rules").TomlHighlightRules;
  107. var FoldMode = require("./folding/ini").FoldMode;
  108. var Mode = function() {
  109. this.HighlightRules = TomlHighlightRules;
  110. this.foldingRules = new FoldMode();
  111. this.$behaviour = this.$defaultBehaviour;
  112. };
  113. oop.inherits(Mode, TextMode);
  114. (function() {
  115. this.lineCommentStart = "#";
  116. this.$id = "ace/mode/toml";
  117. }).call(Mode.prototype);
  118. exports.Mode = Mode;
  119. });
  120. (function() {
  121. ace.require(["ace/mode/toml"], function(m) {
  122. if (typeof module == "object" && typeof exports == "object" && module) {
  123. module.exports = m;
  124. }
  125. });
  126. })();