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