Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50675 views
1
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2
// Distributed under an MIT license: http://codemirror.net/LICENSE
3
4
(function(mod) {
5
if (typeof exports == "object" && typeof module == "object") // CommonJS
6
mod(require("../../lib/codemirror"), require("../../addon/mode/simple"));
7
else if (typeof define == "function" && define.amd) // AMD
8
define(["../../lib/codemirror", "../../addon/mode/simple"], mod);
9
else // Plain browser env
10
mod(CodeMirror);
11
})(function(CodeMirror) {
12
"use strict";
13
14
// Collect all Dockerfile directives
15
var instructions = ["from", "maintainer", "run", "cmd", "expose", "env",
16
"add", "copy", "entrypoint", "volume", "user",
17
"workdir", "onbuild"],
18
instructionRegex = "(" + instructions.join('|') + ")",
19
instructionOnlyLine = new RegExp(instructionRegex + "\\s*$", "i"),
20
instructionWithArguments = new RegExp(instructionRegex + "(\\s+)", "i");
21
22
CodeMirror.defineSimpleMode("dockerfile", {
23
start: [
24
// Block comment: This is a line starting with a comment
25
{
26
regex: /#.*$/,
27
token: "comment"
28
},
29
// Highlight an instruction without any arguments (for convenience)
30
{
31
regex: instructionOnlyLine,
32
token: "variable-2"
33
},
34
// Highlight an instruction followed by arguments
35
{
36
regex: instructionWithArguments,
37
token: ["variable-2", null],
38
next: "arguments"
39
},
40
{
41
regex: /./,
42
token: null
43
}
44
],
45
arguments: [
46
{
47
// Line comment without instruction arguments is an error
48
regex: /#.*$/,
49
token: "error",
50
next: "start"
51
},
52
{
53
regex: /[^#]+\\$/,
54
token: null
55
},
56
{
57
// Match everything except for the inline comment
58
regex: /[^#]+/,
59
token: null,
60
next: "start"
61
},
62
{
63
regex: /$/,
64
token: null,
65
next: "start"
66
},
67
// Fail safe return to start
68
{
69
token: null,
70
next: "start"
71
}
72
]
73
});
74
75
CodeMirror.defineMIME("text/x-dockerfile", "dockerfile");
76
});
77
78