]> luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/bash.js
Initial commit.
[flow-web.git] / static / highlight / es / languages / bash.js
1 /*! `bash` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar = (function () {
3 'use strict';
4
5 /*
6 Language: Bash
7 Author: vah <vahtenberg@gmail.com>
8 Contributrors: Benjamin Pannell <contact@sierrasoftworks.com>
9 Website: https://www.gnu.org/software/bash/
10 Category: common, scripting
11 */
12
13 /** @type LanguageFn */
14 function bash(hljs) {
15 const regex = hljs.regex;
16 const VAR = {};
17 const BRACED_VAR = {
18 begin: /\$\{/,
19 end: /\}/,
20 contains: [
21 "self",
22 {
23 begin: /:-/,
24 contains: [ VAR ]
25 } // default values
26 ]
27 };
28 Object.assign(VAR, {
29 className: 'variable',
30 variants: [
31 { begin: regex.concat(/\$[\w\d#@][\w\d_]*/,
32 // negative look-ahead tries to avoid matching patterns that are not
33 // Perl at all like $ident$, @ident@, etc.
34 `(?![\\w\\d])(?![$])`) },
35 BRACED_VAR
36 ]
37 });
38
39 const SUBST = {
40 className: 'subst',
41 begin: /\$\(/,
42 end: /\)/,
43 contains: [ hljs.BACKSLASH_ESCAPE ]
44 };
45 const COMMENT = hljs.inherit(
46 hljs.COMMENT(),
47 {
48 match: [
49 /(^|\s)/,
50 /#.*$/
51 ],
52 scope: {
53 2: 'comment'
54 }
55 }
56 );
57 const HERE_DOC = {
58 begin: /<<-?\s*(?=\w+)/,
59 starts: { contains: [
60 hljs.END_SAME_AS_BEGIN({
61 begin: /(\w+)/,
62 end: /(\w+)/,
63 className: 'string'
64 })
65 ] }
66 };
67 const QUOTE_STRING = {
68 className: 'string',
69 begin: /"/,
70 end: /"/,
71 contains: [
72 hljs.BACKSLASH_ESCAPE,
73 VAR,
74 SUBST
75 ]
76 };
77 SUBST.contains.push(QUOTE_STRING);
78 const ESCAPED_QUOTE = {
79 match: /\\"/
80 };
81 const APOS_STRING = {
82 className: 'string',
83 begin: /'/,
84 end: /'/
85 };
86 const ESCAPED_APOS = {
87 match: /\\'/
88 };
89 const ARITHMETIC = {
90 begin: /\$?\(\(/,
91 end: /\)\)/,
92 contains: [
93 {
94 begin: /\d+#[0-9a-f]+/,
95 className: "number"
96 },
97 hljs.NUMBER_MODE,
98 VAR
99 ]
100 };
101 const SH_LIKE_SHELLS = [
102 "fish",
103 "bash",
104 "zsh",
105 "sh",
106 "csh",
107 "ksh",
108 "tcsh",
109 "dash",
110 "scsh",
111 ];
112 const KNOWN_SHEBANG = hljs.SHEBANG({
113 binary: `(${SH_LIKE_SHELLS.join("|")})`,
114 relevance: 10
115 });
116 const FUNCTION = {
117 className: 'function',
118 begin: /\w[\w\d_]*\s*\(\s*\)\s*\{/,
119 returnBegin: true,
120 contains: [ hljs.inherit(hljs.TITLE_MODE, { begin: /\w[\w\d_]*/ }) ],
121 relevance: 0
122 };
123
124 const KEYWORDS = [
125 "if",
126 "then",
127 "else",
128 "elif",
129 "fi",
130 "time",
131 "for",
132 "while",
133 "until",
134 "in",
135 "do",
136 "done",
137 "case",
138 "esac",
139 "coproc",
140 "function",
141 "select"
142 ];
143
144 const LITERALS = [
145 "true",
146 "false"
147 ];
148
149 // to consume paths to prevent keyword matches inside them
150 const PATH_MODE = { match: /(\/[a-z._-]+)+/ };
151
152 // http://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
153 const SHELL_BUILT_INS = [
154 "break",
155 "cd",
156 "continue",
157 "eval",
158 "exec",
159 "exit",
160 "export",
161 "getopts",
162 "hash",
163 "pwd",
164 "readonly",
165 "return",
166 "shift",
167 "test",
168 "times",
169 "trap",
170 "umask",
171 "unset"
172 ];
173
174 const BASH_BUILT_INS = [
175 "alias",
176 "bind",
177 "builtin",
178 "caller",
179 "command",
180 "declare",
181 "echo",
182 "enable",
183 "help",
184 "let",
185 "local",
186 "logout",
187 "mapfile",
188 "printf",
189 "read",
190 "readarray",
191 "source",
192 "sudo",
193 "type",
194 "typeset",
195 "ulimit",
196 "unalias"
197 ];
198
199 const ZSH_BUILT_INS = [
200 "autoload",
201 "bg",
202 "bindkey",
203 "bye",
204 "cap",
205 "chdir",
206 "clone",
207 "comparguments",
208 "compcall",
209 "compctl",
210 "compdescribe",
211 "compfiles",
212 "compgroups",
213 "compquote",
214 "comptags",
215 "comptry",
216 "compvalues",
217 "dirs",
218 "disable",
219 "disown",
220 "echotc",
221 "echoti",
222 "emulate",
223 "fc",
224 "fg",
225 "float",
226 "functions",
227 "getcap",
228 "getln",
229 "history",
230 "integer",
231 "jobs",
232 "kill",
233 "limit",
234 "log",
235 "noglob",
236 "popd",
237 "print",
238 "pushd",
239 "pushln",
240 "rehash",
241 "sched",
242 "setcap",
243 "setopt",
244 "stat",
245 "suspend",
246 "ttyctl",
247 "unfunction",
248 "unhash",
249 "unlimit",
250 "unsetopt",
251 "vared",
252 "wait",
253 "whence",
254 "where",
255 "which",
256 "zcompile",
257 "zformat",
258 "zftp",
259 "zle",
260 "zmodload",
261 "zparseopts",
262 "zprof",
263 "zpty",
264 "zregexparse",
265 "zsocket",
266 "zstyle",
267 "ztcp"
268 ];
269
270 const GNU_CORE_UTILS = [
271 "chcon",
272 "chgrp",
273 "chown",
274 "chmod",
275 "cp",
276 "dd",
277 "df",
278 "dir",
279 "dircolors",
280 "ln",
281 "ls",
282 "mkdir",
283 "mkfifo",
284 "mknod",
285 "mktemp",
286 "mv",
287 "realpath",
288 "rm",
289 "rmdir",
290 "shred",
291 "sync",
292 "touch",
293 "truncate",
294 "vdir",
295 "b2sum",
296 "base32",
297 "base64",
298 "cat",
299 "cksum",
300 "comm",
301 "csplit",
302 "cut",
303 "expand",
304 "fmt",
305 "fold",
306 "head",
307 "join",
308 "md5sum",
309 "nl",
310 "numfmt",
311 "od",
312 "paste",
313 "ptx",
314 "pr",
315 "sha1sum",
316 "sha224sum",
317 "sha256sum",
318 "sha384sum",
319 "sha512sum",
320 "shuf",
321 "sort",
322 "split",
323 "sum",
324 "tac",
325 "tail",
326 "tr",
327 "tsort",
328 "unexpand",
329 "uniq",
330 "wc",
331 "arch",
332 "basename",
333 "chroot",
334 "date",
335 "dirname",
336 "du",
337 "echo",
338 "env",
339 "expr",
340 "factor",
341 // "false", // keyword literal already
342 "groups",
343 "hostid",
344 "id",
345 "link",
346 "logname",
347 "nice",
348 "nohup",
349 "nproc",
350 "pathchk",
351 "pinky",
352 "printenv",
353 "printf",
354 "pwd",
355 "readlink",
356 "runcon",
357 "seq",
358 "sleep",
359 "stat",
360 "stdbuf",
361 "stty",
362 "tee",
363 "test",
364 "timeout",
365 // "true", // keyword literal already
366 "tty",
367 "uname",
368 "unlink",
369 "uptime",
370 "users",
371 "who",
372 "whoami",
373 "yes"
374 ];
375
376 return {
377 name: 'Bash',
378 aliases: [
379 'sh',
380 'zsh'
381 ],
382 keywords: {
383 $pattern: /\b[a-z][a-z0-9._-]+\b/,
384 keyword: KEYWORDS,
385 literal: LITERALS,
386 built_in: [
387 ...SHELL_BUILT_INS,
388 ...BASH_BUILT_INS,
389 // Shell modifiers
390 "set",
391 "shopt",
392 ...ZSH_BUILT_INS,
393 ...GNU_CORE_UTILS
394 ]
395 },
396 contains: [
397 KNOWN_SHEBANG, // to catch known shells and boost relevancy
398 hljs.SHEBANG(), // to catch unknown shells but still highlight the shebang
399 FUNCTION,
400 ARITHMETIC,
401 COMMENT,
402 HERE_DOC,
403 PATH_MODE,
404 QUOTE_STRING,
405 ESCAPED_QUOTE,
406 APOS_STRING,
407 ESCAPED_APOS,
408 VAR
409 ]
410 };
411 }
412
413 return bash;
414
415 })();
416 ;
417 export default hljsGrammar;