mode-applescript.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  118. var line = session.getLine(row);
  119. var match = line.match(this.foldingStartMarker);
  120. if (match) {
  121. var i = match.index;
  122. if (match[1])
  123. return this.openingBracketBlock(session, match[1], row, i);
  124. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  125. if (range && !range.isMultiLine()) {
  126. if (forceMultiline) {
  127. range = this.getSectionRange(session, row);
  128. } else if (foldStyle != "all")
  129. range = null;
  130. }
  131. return range;
  132. }
  133. if (foldStyle === "markbegin")
  134. return;
  135. var match = line.match(this.foldingStopMarker);
  136. if (match) {
  137. var i = match.index + match[0].length;
  138. if (match[1])
  139. return this.closingBracketBlock(session, match[1], row, i);
  140. return session.getCommentFoldRange(row, i, -1);
  141. }
  142. };
  143. this.getSectionRange = function(session, row) {
  144. var line = session.getLine(row);
  145. var startIndent = line.search(/\S/);
  146. var startRow = row;
  147. var startColumn = line.length;
  148. row = row + 1;
  149. var endRow = row;
  150. var maxRow = session.getLength();
  151. while (++row < maxRow) {
  152. line = session.getLine(row);
  153. var indent = line.search(/\S/);
  154. if (indent === -1)
  155. continue;
  156. if (startIndent > indent)
  157. break;
  158. var subRange = this.getFoldWidgetRange(session, "all", row);
  159. if (subRange) {
  160. if (subRange.start.row <= startRow) {
  161. break;
  162. } else if (subRange.isMultiLine()) {
  163. row = subRange.end.row;
  164. } else if (startIndent == indent) {
  165. break;
  166. }
  167. }
  168. endRow = row;
  169. }
  170. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  171. };
  172. }).call(FoldMode.prototype);
  173. });
  174. ace.define("ace/mode/applescript",["require","exports","module","ace/lib/oop","ace/mode/text","ace/tokenizer","ace/mode/applescript_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  175. "use strict";
  176. var oop = require("../lib/oop");
  177. var TextMode = require("./text").Mode;
  178. var Tokenizer = require("../tokenizer").Tokenizer;
  179. var AppleScriptHighlightRules = require("./applescript_highlight_rules").AppleScriptHighlightRules;
  180. var FoldMode = require("./folding/cstyle").FoldMode;
  181. var Mode = function() {
  182. this.HighlightRules = AppleScriptHighlightRules;
  183. this.foldingRules = new FoldMode();
  184. };
  185. oop.inherits(Mode, TextMode);
  186. (function() {
  187. this.lineCommentStart = "--";
  188. this.blockComment = {start: "(*", end: "*)"};
  189. this.$id = "ace/mode/applescript";
  190. }).call(Mode.prototype);
  191. exports.Mode = Mode;
  192. });