applescript_highlight_rules.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2012, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. define(function(require, exports, module) {
  31. "use strict";
  32. var oop = require("../lib/oop");
  33. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  34. var AppleScriptHighlightRules = function() {
  35. // regexp must not have capturing parentheses. Use (?:) instead.
  36. // regexps are ordered -> the first match is used
  37. var keywords = (
  38. "about|above|after|against|and|around|as|at|back|before|beginning|" +
  39. "behind|below|beneath|beside|between|but|by|considering|" +
  40. "contain|contains|continue|copy|div|does|eighth|else|end|equal|" +
  41. "equals|error|every|exit|fifth|first|for|fourth|from|front|" +
  42. "get|given|global|if|ignoring|in|into|is|it|its|last|local|me|" +
  43. "middle|mod|my|ninth|not|of|on|onto|or|over|prop|property|put|ref|" +
  44. "reference|repeat|returning|script|second|set|seventh|since|" +
  45. "sixth|some|tell|tenth|that|the|then|third|through|thru|" +
  46. "timeout|times|to|transaction|try|until|where|while|whose|with|without"
  47. );
  48. var builtinConstants = (
  49. "AppleScript|false|linefeed|return|pi|quote|result|space|tab|true"
  50. );
  51. var builtinFunctions = (
  52. "activate|beep|count|delay|launch|log|offset|read|round|run|say|" +
  53. "summarize|write"
  54. );
  55. var builtinTypes = (
  56. "alias|application|boolean|class|constant|date|file|integer|list|" +
  57. "number|real|record|string|text|character|characters|contents|day|" +
  58. "frontmost|id|item|length|month|name|paragraph|paragraphs|rest|" +
  59. "reverse|running|time|version|weekday|word|words|year"
  60. );
  61. var keywordMapper = this.createKeywordMapper({
  62. "support.function": builtinFunctions,
  63. "constant.language": builtinConstants,
  64. "support.type": builtinTypes,
  65. "keyword": keywords
  66. }, "identifier");
  67. this.$rules = {
  68. "start": [
  69. {
  70. token: "comment",
  71. regex: "--.*$"
  72. },
  73. {
  74. token : "comment", // multi line comment
  75. regex : "\\(\\*",
  76. next : "comment"
  77. },
  78. {
  79. token: "string", // " string
  80. regex: '".*?"'
  81. },
  82. {
  83. token: "support.type",
  84. regex: '\\b(POSIX file|POSIX path|(date|time) string|quoted form)\\b'
  85. },
  86. {
  87. token: "support.function",
  88. regex: '\\b(clipboard info|the clipboard|info for|list (disks|folder)|' +
  89. 'mount volume|path to|(close|open for) access|(get|set) eof|' +
  90. 'current date|do shell script|get volume settings|random number|' +
  91. 'set volume|system attribute|system info|time to GMT|' +
  92. '(load|run|store) script|scripting components|' +
  93. 'ASCII (character|number)|localized string|' +
  94. 'choose (application|color|file|file name|' +
  95. 'folder|from list|remote application|URL)|' +
  96. 'display (alert|dialog))\\b|^\\s*return\\b'
  97. },
  98. {
  99. token: "constant.language",
  100. regex: '\\b(text item delimiters|current application|missing value)\\b'
  101. },
  102. {
  103. token: "keyword",
  104. regex: '\\b(apart from|aside from|instead of|out of|greater than|' +
  105. "isn't|(doesn't|does not) (equal|come before|come after|contain)|" +
  106. '(greater|less) than( or equal)?|(starts?|ends|begins?) with|' +
  107. 'contained by|comes (before|after)|a (ref|reference))\\b'
  108. },
  109. {
  110. token: keywordMapper,
  111. regex: "[a-zA-Z][a-zA-Z0-9_]*\\b"
  112. }
  113. ],
  114. "comment": [
  115. {
  116. token: "comment", // closing comment
  117. regex: "\\*\\)",
  118. next: "start"
  119. }, {
  120. defaultToken: "comment"
  121. }
  122. ]
  123. }
  124. this.normalizeRules();
  125. };
  126. oop.inherits(AppleScriptHighlightRules, TextHighlightRules);
  127. exports.AppleScriptHighlightRules = AppleScriptHighlightRules;
  128. });