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