applescript.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. */
  7. /** @type LanguageFn */
  8. function applescript(hljs) {
  9. var STRING = hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: ''});
  10. var PARAMS = {
  11. className: 'params',
  12. begin: '\\(', end: '\\)',
  13. contains: ['self', hljs.C_NUMBER_MODE, STRING]
  14. };
  15. var COMMENT_MODE_1 = hljs.COMMENT('--', '$');
  16. var COMMENT_MODE_2 = hljs.COMMENT(
  17. '\\(\\*',
  18. '\\*\\)',
  19. {
  20. contains: ['self', COMMENT_MODE_1] //allow nesting
  21. }
  22. );
  23. var COMMENTS = [
  24. COMMENT_MODE_1,
  25. COMMENT_MODE_2,
  26. hljs.HASH_COMMENT_MODE
  27. ];
  28. return {
  29. name: 'AppleScript',
  30. aliases: ['osascript'],
  31. keywords: {
  32. keyword:
  33. 'about above after against and around as at back before beginning ' +
  34. 'behind below beneath beside between but by considering ' +
  35. 'contain contains continue copy div does eighth else end equal ' +
  36. 'equals error every exit fifth first for fourth from front ' +
  37. 'get given global if ignoring in into is it its last local me ' +
  38. 'middle mod my ninth not of on onto or over prop property put ref ' +
  39. 'reference repeat returning script second set seventh since ' +
  40. 'sixth some tell tenth that the|0 then third through thru ' +
  41. 'timeout times to transaction try until where while whose with ' +
  42. 'without',
  43. literal:
  44. 'AppleScript false linefeed return pi quote result space tab true',
  45. built_in:
  46. 'alias application boolean class constant date file integer list ' +
  47. 'number real record string text ' +
  48. 'activate beep count delay launch log offset read round ' +
  49. 'run say summarize write ' +
  50. 'character characters contents day frontmost id item length ' +
  51. 'month name paragraph paragraphs rest reverse running time version ' +
  52. 'weekday word words year'
  53. },
  54. contains: [
  55. STRING,
  56. hljs.C_NUMBER_MODE,
  57. {
  58. className: 'built_in',
  59. begin:
  60. '\\b(clipboard info|the clipboard|info for|list (disks|folder)|' +
  61. 'mount volume|path to|(close|open for) access|(get|set) eof|' +
  62. 'current date|do shell script|get volume settings|random number|' +
  63. 'set volume|system attribute|system info|time to GMT|' +
  64. '(load|run|store) script|scripting components|' +
  65. 'ASCII (character|number)|localized string|' +
  66. 'choose (application|color|file|file name|' +
  67. 'folder|from list|remote application|URL)|' +
  68. 'display (alert|dialog))\\b|^\\s*return\\b'
  69. },
  70. {
  71. className: 'literal',
  72. begin:
  73. '\\b(text item delimiters|current application|missing value)\\b'
  74. },
  75. {
  76. className: 'keyword',
  77. begin:
  78. '\\b(apart from|aside from|instead of|out of|greater than|' +
  79. "isn't|(doesn't|does not) (equal|come before|come after|contain)|" +
  80. '(greater|less) than( or equal)?|(starts?|ends|begins?) with|' +
  81. 'contained by|comes (before|after)|a (ref|reference)|POSIX file|' +
  82. 'POSIX path|(date|time) string|quoted form)\\b'
  83. },
  84. {
  85. beginKeywords: 'on',
  86. illegal: '[${=;\\n]',
  87. contains: [hljs.UNDERSCORE_TITLE_MODE, PARAMS]
  88. }
  89. ].concat(COMMENTS),
  90. illegal: '//|->|=>|\\[\\['
  91. };
  92. }
  93. module.exports = applescript;