| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  | // CodeMirror, copyright (c) by Marijn Haverbeke and others
 | 
					
						
							| 
									
										
										
										
											2022-10-15 12:22:09 +02:00
										 |  |  | // Distributed under an MIT license: https://codemirror.net/5/LICENSE
 | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | (function(mod) { | 
					
						
							|  |  |  |   if (typeof exports == "object" && typeof module == "object") // CommonJS
 | 
					
						
							|  |  |  |     mod(require("../../lib/codemirror"), require("../../addon/mode/simple")); | 
					
						
							|  |  |  |   else if (typeof define == "function" && define.amd) // AMD
 | 
					
						
							|  |  |  |     define(["../../lib/codemirror", "../../addon/mode/simple"], mod); | 
					
						
							|  |  |  |   else // Plain browser env
 | 
					
						
							|  |  |  |     mod(CodeMirror); | 
					
						
							|  |  |  | })(function(CodeMirror) { | 
					
						
							|  |  |  |   "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |   var from = "from"; | 
					
						
							|  |  |  |   var fromRegex = new RegExp("^(\\s*)\\b(" + from + ")\\b", "i"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var shells = ["run", "cmd", "entrypoint", "shell"]; | 
					
						
							|  |  |  |   var shellsAsArrayRegex = new RegExp("^(\\s*)(" + shells.join('|') + ")(\\s+\\[)", "i"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var expose = "expose"; | 
					
						
							|  |  |  |   var exposeRegex = new RegExp("^(\\s*)(" + expose + ")(\\s+)", "i"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var others = [ | 
					
						
							|  |  |  |     "arg", "from", "maintainer", "label", "env", | 
					
						
							|  |  |  |     "add", "copy", "volume", "user", | 
					
						
							|  |  |  |     "workdir", "onbuild", "stopsignal", "healthcheck", "shell" | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |   // Collect all Dockerfile directives
 | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |   var instructions = [from, expose].concat(shells).concat(others), | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       instructionRegex = "(" + instructions.join('|') + ")", | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |       instructionOnlyLine = new RegExp("^(\\s*)" + instructionRegex + "(\\s*)(#.*)?$", "i"), | 
					
						
							|  |  |  |       instructionWithArguments = new RegExp("^(\\s*)" + instructionRegex + "(\\s+)", "i"); | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   CodeMirror.defineSimpleMode("dockerfile", { | 
					
						
							|  |  |  |     start: [ | 
					
						
							|  |  |  |       // Block comment: This is a line starting with a comment
 | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |         regex: /^\s*#.*$/, | 
					
						
							|  |  |  |         sol: true, | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |         token: "comment" | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |       { | 
					
						
							|  |  |  |         regex: fromRegex, | 
					
						
							|  |  |  |         token: [null, "keyword"], | 
					
						
							|  |  |  |         sol: true, | 
					
						
							|  |  |  |         next: "from" | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       // Highlight an instruction without any arguments (for convenience)
 | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: instructionOnlyLine, | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |         token: [null, "keyword", null, "error"], | 
					
						
							|  |  |  |         sol: true | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: shellsAsArrayRegex, | 
					
						
							|  |  |  |         token: [null, "keyword", null], | 
					
						
							|  |  |  |         sol: true, | 
					
						
							|  |  |  |         next: "array" | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: exposeRegex, | 
					
						
							|  |  |  |         token: [null, "keyword", null], | 
					
						
							|  |  |  |         sol: true, | 
					
						
							|  |  |  |         next: "expose" | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       }, | 
					
						
							|  |  |  |       // Highlight an instruction followed by arguments
 | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: instructionWithArguments, | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |         token: [null, "keyword", null], | 
					
						
							|  |  |  |         sol: true, | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |         next: "arguments" | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /./, | 
					
						
							|  |  |  |         token: null | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ], | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |     from: [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /\s*$/, | 
					
						
							|  |  |  |         token: null, | 
					
						
							|  |  |  |         next: "start" | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       { | 
					
						
							|  |  |  |         // Line comment without instruction arguments is an error
 | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |         regex: /(\s*)(#.*)$/, | 
					
						
							|  |  |  |         token: [null, "error"], | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |         next: "start" | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |         regex: /(\s*\S+\s+)(as)/i, | 
					
						
							|  |  |  |         token: [null, "keyword"], | 
					
						
							|  |  |  |         next: "start" | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |       // Fail safe return to start
 | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       { | 
					
						
							|  |  |  |         token: null, | 
					
						
							|  |  |  |         next: "start" | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |     single: [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /(?:[^\\']|\\.)/, | 
					
						
							|  |  |  |         token: "string" | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |         regex: /'/, | 
					
						
							|  |  |  |         token: "string", | 
					
						
							|  |  |  |         pop: true | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |     double: [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /(?:[^\\"]|\\.)/, | 
					
						
							|  |  |  |         token: "string" | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /"/, | 
					
						
							|  |  |  |         token: "string", | 
					
						
							|  |  |  |         pop: true | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |     array: [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /\]/, | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |         token: null, | 
					
						
							|  |  |  |         next: "start" | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |       { | 
					
						
							|  |  |  |         regex: /"(?:[^\\"]|\\.)*"?/, | 
					
						
							|  |  |  |         token: "string" | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |     expose: [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /\d+$/, | 
					
						
							|  |  |  |         token: "number", | 
					
						
							|  |  |  |         next: "start" | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /[^\d]+$/, | 
					
						
							|  |  |  |         token: null, | 
					
						
							|  |  |  |         next: "start" | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /\d+/, | 
					
						
							|  |  |  |         token: "number" | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /[^\d]+/, | 
					
						
							|  |  |  |         token: null | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       // Fail safe return to start
 | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         token: null, | 
					
						
							|  |  |  |         next: "start" | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ], | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |     arguments: [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /^\s*#.*$/, | 
					
						
							|  |  |  |         sol: true, | 
					
						
							|  |  |  |         token: "comment" | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /"(?:[^\\"]|\\.)*"?$/, | 
					
						
							|  |  |  |         token: "string", | 
					
						
							|  |  |  |         next: "start" | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /"/, | 
					
						
							|  |  |  |         token: "string", | 
					
						
							|  |  |  |         push: "double" | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /'(?:[^\\']|\\.)*'?$/, | 
					
						
							|  |  |  |         token: "string", | 
					
						
							|  |  |  |         next: "start" | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /'/, | 
					
						
							|  |  |  |         token: "string", | 
					
						
							|  |  |  |         push: "single" | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /[^#"']+[\\`]$/, | 
					
						
							|  |  |  |         token: null | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /[^#"']+$/, | 
					
						
							|  |  |  |         token: null, | 
					
						
							|  |  |  |         next: "start" | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         regex: /[^#"']+/, | 
					
						
							|  |  |  |         token: null | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       // Fail safe return to start
 | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         token: null, | 
					
						
							|  |  |  |         next: "start" | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-15 11:25:30 +02:00
										 |  |  |     ], | 
					
						
							|  |  |  |     meta: { | 
					
						
							|  |  |  |       lineComment: "#" | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   CodeMirror.defineMIME("text/x-dockerfile", "dockerfile"); | 
					
						
							|  |  |  | }); |