dockerfile.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. meta: {
  71. lineComment: "#"
  72. }
  73. });
  74. CodeMirror.defineMIME("text/x-dockerfile", "dockerfile");
  75. });