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. next: "start"
  26. },
  27. // Highlight an instruction without any arguments (for convenience)
  28. {
  29. regex: instructionOnlyLine,
  30. token: "variable-2",
  31. next: "start"
  32. },
  33. // Highlight an instruction followed by arguments
  34. {
  35. regex: instructionWithArguments,
  36. token: ["variable-2", null],
  37. next: "arguments"
  38. },
  39. // Fail-safe return to start
  40. {
  41. token: null,
  42. next: "start"
  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. next: "arguments"
  56. },
  57. {
  58. // Match everything except for the inline comment
  59. regex: /[^#]+/,
  60. token: null,
  61. next: "start"
  62. },
  63. {
  64. regex: /$/,
  65. token: null,
  66. next: "start"
  67. },
  68. // Fail safe return to start
  69. {
  70. token: null,
  71. next: "start"
  72. }
  73. ]
  74. });
  75. CodeMirror.defineMIME("text/x-dockerfile", "dockerfile");
  76. });