mode-applescript.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. ace.define("ace/mode/applescript_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 AppleScriptHighlightRules = function() {
  6. var keywords = (
  7. "about|above|after|against|and|around|as|at|back|before|beginning|" +
  8. "behind|below|beneath|beside|between|but|by|considering|" +
  9. "contain|contains|continue|copy|div|does|eighth|else|end|equal|" +
  10. "equals|error|every|exit|fifth|first|for|fourth|from|front|" +
  11. "get|given|global|if|ignoring|in|into|is|it|its|last|local|me|" +
  12. "middle|mod|my|ninth|not|of|on|onto|or|over|prop|property|put|ref|" +
  13. "reference|repeat|returning|script|second|set|seventh|since|" +
  14. "sixth|some|tell|tenth|that|the|then|third|through|thru|" +
  15. "timeout|times|to|transaction|try|until|where|while|whose|with|without"
  16. );
  17. var builtinConstants = (
  18. "AppleScript|false|linefeed|return|pi|quote|result|space|tab|true"
  19. );
  20. var builtinFunctions = (
  21. "activate|beep|count|delay|launch|log|offset|read|round|run|say|" +
  22. "summarize|write"
  23. );
  24. var builtinTypes = (
  25. "alias|application|boolean|class|constant|date|file|integer|list|" +
  26. "number|real|record|string|text|character|characters|contents|day|" +
  27. "frontmost|id|item|length|month|name|paragraph|paragraphs|rest|" +
  28. "reverse|running|time|version|weekday|word|words|year"
  29. );
  30. var keywordMapper = this.createKeywordMapper({
  31. "support.function": builtinFunctions,
  32. "constant.language": builtinConstants,
  33. "support.type": builtinTypes,
  34. "keyword": keywords
  35. }, "identifier");
  36. this.$rules = {
  37. "start": [
  38. {
  39. token: "comment",
  40. regex: "--.*$"
  41. },
  42. {
  43. token : "comment", // multi line comment
  44. regex : "\\(\\*",
  45. next : "comment"
  46. },
  47. {
  48. token: "string", // " string
  49. regex: '".*?"'
  50. },
  51. {
  52. token: "support.type",
  53. regex: '\\b(POSIX file|POSIX path|(date|time) string|quoted form)\\b'
  54. },
  55. {
  56. token: "support.function",
  57. regex: '\\b(clipboard info|the clipboard|info for|list (disks|folder)|' +
  58. 'mount volume|path to|(close|open for) access|(get|set) eof|' +
  59. 'current date|do shell script|get volume settings|random number|' +
  60. 'set volume|system attribute|system info|time to GMT|' +
  61. '(load|run|store) script|scripting components|' +
  62. 'ASCII (character|number)|localized string|' +
  63. 'choose (application|color|file|file name|' +
  64. 'folder|from list|remote application|URL)|' +
  65. 'display (alert|dialog))\\b|^\\s*return\\b'
  66. },
  67. {
  68. token: "constant.language",
  69. regex: '\\b(text item delimiters|current application|missing value)\\b'
  70. },
  71. {
  72. token: "keyword",
  73. regex: '\\b(apart from|aside from|instead of|out of|greater than|' +
  74. "isn't|(doesn't|does not) (equal|come before|come after|contain)|" +
  75. '(greater|less) than( or equal)?|(starts?|ends|begins?) with|' +
  76. 'contained by|comes (before|after)|a (ref|reference))\\b'
  77. },
  78. {
  79. token: keywordMapper,
  80. regex: "[a-zA-Z][a-zA-Z0-9_]*\\b"
  81. }
  82. ],
  83. "comment": [
  84. {
  85. token: "comment", // closing comment
  86. regex: "\\*\\)",
  87. next: "start"
  88. }, {
  89. defaultToken: "comment"
  90. }
  91. ]
  92. }
  93. this.normalizeRules();
  94. };
  95. oop.inherits(AppleScriptHighlightRules, TextHighlightRules);
  96. exports.AppleScriptHighlightRules = AppleScriptHighlightRules;
  97. });
  98. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  99. "use strict";
  100. var oop = require("../../lib/oop");
  101. var Range = require("../../range").Range;
  102. var BaseFoldMode = require("./fold_mode").FoldMode;
  103. var FoldMode = exports.FoldMode = function(commentRegex) {
  104. if (commentRegex) {
  105. this.foldingStartMarker = new RegExp(
  106. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  107. );
  108. this.foldingStopMarker = new RegExp(
  109. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  110. );
  111. }
  112. };
  113. oop.inherits(FoldMode, BaseFoldMode);
  114. (function() {
  115. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  116. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  117. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  118. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  119. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  120. this._getFoldWidgetBase = this.getFoldWidget;
  121. this.getFoldWidget = function(session, foldStyle, row) {
  122. var line = session.getLine(row);
  123. if (this.singleLineBlockCommentRe.test(line)) {
  124. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  125. return "";
  126. }
  127. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  128. if (!fw && this.startRegionRe.test(line))
  129. return "start"; // lineCommentRegionStart
  130. return fw;
  131. };
  132. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  133. var line = session.getLine(row);
  134. if (this.startRegionRe.test(line))
  135. return this.getCommentRegionBlock(session, line, row);
  136. var match = line.match(this.foldingStartMarker);
  137. if (match) {
  138. var i = match.index;
  139. if (match[1])
  140. return this.openingBracketBlock(session, match[1], row, i);
  141. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  142. if (range && !range.isMultiLine()) {
  143. if (forceMultiline) {
  144. range = this.getSectionRange(session, row);
  145. } else if (foldStyle != "all")
  146. range = null;
  147. }
  148. return range;
  149. }
  150. if (foldStyle === "markbegin")
  151. return;
  152. var match = line.match(this.foldingStopMarker);
  153. if (match) {
  154. var i = match.index + match[0].length;
  155. if (match[1])
  156. return this.closingBracketBlock(session, match[1], row, i);
  157. return session.getCommentFoldRange(row, i, -1);
  158. }
  159. };
  160. this.getSectionRange = function(session, row) {
  161. var line = session.getLine(row);
  162. var startIndent = line.search(/\S/);
  163. var startRow = row;
  164. var startColumn = line.length;
  165. row = row + 1;
  166. var endRow = row;
  167. var maxRow = session.getLength();
  168. while (++row < maxRow) {
  169. line = session.getLine(row);
  170. var indent = line.search(/\S/);
  171. if (indent === -1)
  172. continue;
  173. if (startIndent > indent)
  174. break;
  175. var subRange = this.getFoldWidgetRange(session, "all", row);
  176. if (subRange) {
  177. if (subRange.start.row <= startRow) {
  178. break;
  179. } else if (subRange.isMultiLine()) {
  180. row = subRange.end.row;
  181. } else if (startIndent == indent) {
  182. break;
  183. }
  184. }
  185. endRow = row;
  186. }
  187. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  188. };
  189. this.getCommentRegionBlock = function(session, line, row) {
  190. var startColumn = line.search(/\s*$/);
  191. var maxRow = session.getLength();
  192. var startRow = row;
  193. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  194. var depth = 1;
  195. while (++row < maxRow) {
  196. line = session.getLine(row);
  197. var m = re.exec(line);
  198. if (!m) continue;
  199. if (m[1]) depth--;
  200. else depth++;
  201. if (!depth) break;
  202. }
  203. var endRow = row;
  204. if (endRow > startRow) {
  205. return new Range(startRow, startColumn, endRow, line.length);
  206. }
  207. };
  208. }).call(FoldMode.prototype);
  209. });
  210. ace.define("ace/mode/applescript",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/applescript_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  211. "use strict";
  212. var oop = require("../lib/oop");
  213. var TextMode = require("./text").Mode;
  214. var AppleScriptHighlightRules = require("./applescript_highlight_rules").AppleScriptHighlightRules;
  215. var FoldMode = require("./folding/cstyle").FoldMode;
  216. var Mode = function() {
  217. this.HighlightRules = AppleScriptHighlightRules;
  218. this.foldingRules = new FoldMode();
  219. this.$behaviour = this.$defaultBehaviour;
  220. };
  221. oop.inherits(Mode, TextMode);
  222. (function() {
  223. this.lineCommentStart = "--";
  224. this.blockComment = {start: "(*", end: "*)"};
  225. this.$id = "ace/mode/applescript";
  226. }).call(Mode.prototype);
  227. exports.Mode = Mode;
  228. });