1 | 'use strict'
|
---|
2 |
|
---|
3 | module.exports = docker
|
---|
4 | docker.displayName = 'docker'
|
---|
5 | docker.aliases = ['dockerfile']
|
---|
6 | function docker(Prism) {
|
---|
7 | ;(function (Prism) {
|
---|
8 | // Many of the following regexes will contain negated lookaheads like `[ \t]+(?![ \t])`. This is a trick to ensure
|
---|
9 | // that quantifiers behave *atomically*. Atomic quantifiers are necessary to prevent exponential backtracking.
|
---|
10 | var spaceAfterBackSlash =
|
---|
11 | /\\[\r\n](?:\s|\\[\r\n]|#.*(?!.))*(?![\s#]|\\[\r\n])/.source // At least one space, comment, or line break
|
---|
12 | var space = /(?:[ \t]+(?![ \t])(?:<SP_BS>)?|<SP_BS>)/.source.replace(
|
---|
13 | /<SP_BS>/g,
|
---|
14 | function () {
|
---|
15 | return spaceAfterBackSlash
|
---|
16 | }
|
---|
17 | )
|
---|
18 | var string =
|
---|
19 | /"(?:[^"\\\r\n]|\\(?:\r\n|[\s\S]))*"|'(?:[^'\\\r\n]|\\(?:\r\n|[\s\S]))*'/
|
---|
20 | .source
|
---|
21 | var option = /--[\w-]+=(?:<STR>|(?!["'])(?:[^\s\\]|\\.)+)/.source.replace(
|
---|
22 | /<STR>/g,
|
---|
23 | function () {
|
---|
24 | return string
|
---|
25 | }
|
---|
26 | )
|
---|
27 | var stringRule = {
|
---|
28 | pattern: RegExp(string),
|
---|
29 | greedy: true
|
---|
30 | }
|
---|
31 | var commentRule = {
|
---|
32 | pattern: /(^[ \t]*)#.*/m,
|
---|
33 | lookbehind: true,
|
---|
34 | greedy: true
|
---|
35 | }
|
---|
36 | /**
|
---|
37 | * @param {string} source
|
---|
38 | * @param {string} flags
|
---|
39 | * @returns {RegExp}
|
---|
40 | */
|
---|
41 | function re(source, flags) {
|
---|
42 | source = source
|
---|
43 | .replace(/<OPT>/g, function () {
|
---|
44 | return option
|
---|
45 | })
|
---|
46 | .replace(/<SP>/g, function () {
|
---|
47 | return space
|
---|
48 | })
|
---|
49 | return RegExp(source, flags)
|
---|
50 | }
|
---|
51 | Prism.languages.docker = {
|
---|
52 | instruction: {
|
---|
53 | pattern:
|
---|
54 | /(^[ \t]*)(?:ADD|ARG|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|HEALTHCHECK|LABEL|MAINTAINER|ONBUILD|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR)(?=\s)(?:\\.|[^\r\n\\])*(?:\\$(?:\s|#.*$)*(?![\s#])(?:\\.|[^\r\n\\])*)*/im,
|
---|
55 | lookbehind: true,
|
---|
56 | greedy: true,
|
---|
57 | inside: {
|
---|
58 | options: {
|
---|
59 | pattern: re(
|
---|
60 | /(^(?:ONBUILD<SP>)?\w+<SP>)<OPT>(?:<SP><OPT>)*/.source,
|
---|
61 | 'i'
|
---|
62 | ),
|
---|
63 | lookbehind: true,
|
---|
64 | greedy: true,
|
---|
65 | inside: {
|
---|
66 | property: {
|
---|
67 | pattern: /(^|\s)--[\w-]+/,
|
---|
68 | lookbehind: true
|
---|
69 | },
|
---|
70 | string: [
|
---|
71 | stringRule,
|
---|
72 | {
|
---|
73 | pattern: /(=)(?!["'])(?:[^\s\\]|\\.)+/,
|
---|
74 | lookbehind: true
|
---|
75 | }
|
---|
76 | ],
|
---|
77 | operator: /\\$/m,
|
---|
78 | punctuation: /=/
|
---|
79 | }
|
---|
80 | },
|
---|
81 | keyword: [
|
---|
82 | {
|
---|
83 | // https://docs.docker.com/engine/reference/builder/#healthcheck
|
---|
84 | pattern: re(
|
---|
85 | /(^(?:ONBUILD<SP>)?HEALTHCHECK<SP>(?:<OPT><SP>)*)(?:CMD|NONE)\b/
|
---|
86 | .source,
|
---|
87 | 'i'
|
---|
88 | ),
|
---|
89 | lookbehind: true,
|
---|
90 | greedy: true
|
---|
91 | },
|
---|
92 | {
|
---|
93 | // https://docs.docker.com/engine/reference/builder/#from
|
---|
94 | pattern: re(
|
---|
95 | /(^(?:ONBUILD<SP>)?FROM<SP>(?:<OPT><SP>)*(?!--)[^ \t\\]+<SP>)AS/
|
---|
96 | .source,
|
---|
97 | 'i'
|
---|
98 | ),
|
---|
99 | lookbehind: true,
|
---|
100 | greedy: true
|
---|
101 | },
|
---|
102 | {
|
---|
103 | // https://docs.docker.com/engine/reference/builder/#onbuild
|
---|
104 | pattern: re(/(^ONBUILD<SP>)\w+/.source, 'i'),
|
---|
105 | lookbehind: true,
|
---|
106 | greedy: true
|
---|
107 | },
|
---|
108 | {
|
---|
109 | pattern: /^\w+/,
|
---|
110 | greedy: true
|
---|
111 | }
|
---|
112 | ],
|
---|
113 | comment: commentRule,
|
---|
114 | string: stringRule,
|
---|
115 | variable: /\$(?:\w+|\{[^{}"'\\]*\})/,
|
---|
116 | operator: /\\$/m
|
---|
117 | }
|
---|
118 | },
|
---|
119 | comment: commentRule
|
---|
120 | }
|
---|
121 | Prism.languages.dockerfile = Prism.languages.docker
|
---|
122 | })(Prism)
|
---|
123 | }
|
---|