applescript.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. Language: AppleScript
  3. Authors: Nathan Grigg <nathan@nathanamy.org>, Dr. Drang <drdrang@gmail.com>
  4. Category: scripting
  5. Website: https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html
  6. Audit: 2020
  7. */
  8. /** @type LanguageFn */
  9. function applescript(hljs) {
  10. const regex = hljs.regex;
  11. const STRING = hljs.inherit(
  12. hljs.QUOTE_STRING_MODE, { illegal: null });
  13. const PARAMS = {
  14. className: 'params',
  15. begin: /\(/,
  16. end: /\)/,
  17. contains: [
  18. 'self',
  19. hljs.C_NUMBER_MODE,
  20. STRING
  21. ]
  22. };
  23. const COMMENT_MODE_1 = hljs.COMMENT(/--/, /$/);
  24. const COMMENT_MODE_2 = hljs.COMMENT(
  25. /\(\*/,
  26. /\*\)/,
  27. { contains: [
  28. 'self', // allow nesting
  29. COMMENT_MODE_1
  30. ] }
  31. );
  32. const COMMENTS = [
  33. COMMENT_MODE_1,
  34. COMMENT_MODE_2,
  35. hljs.HASH_COMMENT_MODE
  36. ];
  37. const KEYWORD_PATTERNS = [
  38. /apart from/,
  39. /aside from/,
  40. /instead of/,
  41. /out of/,
  42. /greater than/,
  43. /isn't|(doesn't|does not) (equal|come before|come after|contain)/,
  44. /(greater|less) than( or equal)?/,
  45. /(starts?|ends|begins?) with/,
  46. /contained by/,
  47. /comes (before|after)/,
  48. /a (ref|reference)/,
  49. /POSIX (file|path)/,
  50. /(date|time) string/,
  51. /quoted form/
  52. ];
  53. const BUILT_IN_PATTERNS = [
  54. /clipboard info/,
  55. /the clipboard/,
  56. /info for/,
  57. /list (disks|folder)/,
  58. /mount volume/,
  59. /path to/,
  60. /(close|open for) access/,
  61. /(get|set) eof/,
  62. /current date/,
  63. /do shell script/,
  64. /get volume settings/,
  65. /random number/,
  66. /set volume/,
  67. /system attribute/,
  68. /system info/,
  69. /time to GMT/,
  70. /(load|run|store) script/,
  71. /scripting components/,
  72. /ASCII (character|number)/,
  73. /localized string/,
  74. /choose (application|color|file|file name|folder|from list|remote application|URL)/,
  75. /display (alert|dialog)/
  76. ];
  77. return {
  78. name: 'AppleScript',
  79. aliases: [ 'osascript' ],
  80. keywords: {
  81. keyword:
  82. 'about above after against and around as at back before beginning '
  83. + 'behind below beneath beside between but by considering '
  84. + 'contain contains continue copy div does eighth else end equal '
  85. + 'equals error every exit fifth first for fourth from front '
  86. + 'get given global if ignoring in into is it its last local me '
  87. + 'middle mod my ninth not of on onto or over prop property put ref '
  88. + 'reference repeat returning script second set seventh since '
  89. + 'sixth some tell tenth that the|0 then third through thru '
  90. + 'timeout times to transaction try until where while whose with '
  91. + 'without',
  92. literal:
  93. 'AppleScript false linefeed return pi quote result space tab true',
  94. built_in:
  95. 'alias application boolean class constant date file integer list '
  96. + 'number real record string text '
  97. + 'activate beep count delay launch log offset read round '
  98. + 'run say summarize write '
  99. + 'character characters contents day frontmost id item length '
  100. + 'month name|0 paragraph paragraphs rest reverse running time version '
  101. + 'weekday word words year'
  102. },
  103. contains: [
  104. STRING,
  105. hljs.C_NUMBER_MODE,
  106. {
  107. className: 'built_in',
  108. begin: regex.concat(
  109. /\b/,
  110. regex.either(...BUILT_IN_PATTERNS),
  111. /\b/
  112. )
  113. },
  114. {
  115. className: 'built_in',
  116. begin: /^\s*return\b/
  117. },
  118. {
  119. className: 'literal',
  120. begin:
  121. /\b(text item delimiters|current application|missing value)\b/
  122. },
  123. {
  124. className: 'keyword',
  125. begin: regex.concat(
  126. /\b/,
  127. regex.either(...KEYWORD_PATTERNS),
  128. /\b/
  129. )
  130. },
  131. {
  132. beginKeywords: 'on',
  133. illegal: /[${=;\n]/,
  134. contains: [
  135. hljs.UNDERSCORE_TITLE_MODE,
  136. PARAMS
  137. ]
  138. },
  139. ...COMMENTS
  140. ],
  141. illegal: /\/\/|->|=>|\[\[/
  142. };
  143. }
  144. export { applescript as default };