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