dockerfile.js 2.1 KB

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