mode-ini.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. ace.define("ace/mode/ini_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 escapeRe = "\\\\(?:[\\\\0abtrn;#=:]|x[a-fA-F\\d]{4})";
  6. var IniHighlightRules = function() {
  7. this.$rules = {
  8. start: [{
  9. token: 'punctuation.definition.comment.ini',
  10. regex: '#.*',
  11. push_: [{
  12. token: 'comment.line.number-sign.ini',
  13. regex: '$|^',
  14. next: 'pop'
  15. }, {
  16. defaultToken: 'comment.line.number-sign.ini'
  17. }]
  18. }, {
  19. token: 'punctuation.definition.comment.ini',
  20. regex: ';.*',
  21. push_: [{
  22. token: 'comment.line.semicolon.ini',
  23. regex: '$|^',
  24. next: 'pop'
  25. }, {
  26. defaultToken: 'comment.line.semicolon.ini'
  27. }]
  28. }, {
  29. token: ['keyword.other.definition.ini', 'text', 'punctuation.separator.key-value.ini'],
  30. regex: '\\b([a-zA-Z0-9_.-]+)\\b(\\s*)(=)'
  31. }, {
  32. token: ['punctuation.definition.entity.ini', 'constant.section.group-title.ini', 'punctuation.definition.entity.ini'],
  33. regex: '^(\\[)(.*?)(\\])'
  34. }, {
  35. token: 'punctuation.definition.string.begin.ini',
  36. regex: "'",
  37. push: [{
  38. token: 'punctuation.definition.string.end.ini',
  39. regex: "'",
  40. next: 'pop'
  41. }, {
  42. token: "constant.language.escape",
  43. regex: escapeRe
  44. }, {
  45. defaultToken: 'string.quoted.single.ini'
  46. }]
  47. }, {
  48. token: 'punctuation.definition.string.begin.ini',
  49. regex: '"',
  50. push: [{
  51. token: "constant.language.escape",
  52. regex: escapeRe
  53. }, {
  54. token: 'punctuation.definition.string.end.ini',
  55. regex: '"',
  56. next: 'pop'
  57. }, {
  58. defaultToken: 'string.quoted.double.ini'
  59. }]
  60. }]
  61. };
  62. this.normalizeRules();
  63. };
  64. IniHighlightRules.metaData = {
  65. fileTypes: ['ini', 'conf'],
  66. keyEquivalent: '^~I',
  67. name: 'Ini',
  68. scopeName: 'source.ini'
  69. };
  70. oop.inherits(IniHighlightRules, TextHighlightRules);
  71. exports.IniHighlightRules = IniHighlightRules;
  72. });
  73. ace.define("ace/mode/folding/ini",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  74. "use strict";
  75. var oop = require("../../lib/oop");
  76. var Range = require("../../range").Range;
  77. var BaseFoldMode = require("./fold_mode").FoldMode;
  78. var FoldMode = exports.FoldMode = function() {
  79. };
  80. oop.inherits(FoldMode, BaseFoldMode);
  81. (function() {
  82. this.foldingStartMarker = /^\s*\[([^\])]*)]\s*(?:$|[;#])/;
  83. this.getFoldWidgetRange = function(session, foldStyle, row) {
  84. var re = this.foldingStartMarker;
  85. var line = session.getLine(row);
  86. var m = line.match(re);
  87. if (!m) return;
  88. var startName = m[1] + ".";
  89. var startColumn = line.length;
  90. var maxRow = session.getLength();
  91. var startRow = row;
  92. var endRow = row;
  93. while (++row < maxRow) {
  94. line = session.getLine(row);
  95. if (/^\s*$/.test(line))
  96. continue;
  97. m = line.match(re);
  98. if (m && m[1].lastIndexOf(startName, 0) !== 0)
  99. break;
  100. endRow = row;
  101. }
  102. if (endRow > startRow) {
  103. var endColumn = session.getLine(endRow).length;
  104. return new Range(startRow, startColumn, endRow, endColumn);
  105. }
  106. };
  107. }).call(FoldMode.prototype);
  108. });
  109. ace.define("ace/mode/ini",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/ini_highlight_rules","ace/mode/folding/ini"], function(require, exports, module) {
  110. "use strict";
  111. var oop = require("../lib/oop");
  112. var TextMode = require("./text").Mode;
  113. var IniHighlightRules = require("./ini_highlight_rules").IniHighlightRules;
  114. var FoldMode = require("./folding/ini").FoldMode;
  115. var Mode = function() {
  116. this.HighlightRules = IniHighlightRules;
  117. this.foldingRules = new FoldMode();
  118. this.$behaviour = this.$defaultBehaviour;
  119. };
  120. oop.inherits(Mode, TextMode);
  121. (function() {
  122. this.lineCommentStart = ";";
  123. this.blockComment = null;
  124. this.$id = "ace/mode/ini";
  125. }).call(Mode.prototype);
  126. exports.Mode = Mode;
  127. });