cisco-config.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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"));
  6. else if (typeof define == "function" && define.amd) // AMD
  7. define(["../../lib/codemirror"], mod);
  8. else // Plain browser env
  9. mod(CodeMirror);
  10. })(function(CodeMirror) {
  11. "use strict";
  12. CodeMirror.defineMode("cisco-config", function() {
  13. return {
  14. token: function(stream, state) {
  15. var sol = stream.sol() || state.afterSection;
  16. var eol = stream.eol();
  17. state.afterSection = false;
  18. if (sol) {
  19. if (state.nextMultiline) {
  20. state.inMultiline = true;
  21. state.nextMultiline = false;
  22. } else {
  23. state.position = "def";
  24. }
  25. }
  26. if (eol && ! state.nextMultiline) {
  27. state.inMultiline = false;
  28. state.position = "def";
  29. }
  30. if (sol) {
  31. while(stream.eatSpace());
  32. }
  33. var ch = stream.next();
  34. if (sol && (ch === "!")) {
  35. state.position = "comment";
  36. stream.skipToEnd();
  37. return "comment";
  38. } else if (sol && !ch.match(/\s/)) {
  39. state.position = "header";
  40. stream.skipToEnd();
  41. return "header";
  42. }
  43. return state.position;
  44. },
  45. startState: function() {
  46. return {
  47. position : "def", // Current position, "def", "quote" or "comment"
  48. nextMultiline : false, // Is the next line multiline value
  49. inMultiline : false, // Is the current line a multiline value
  50. afterSection : false // Did we just open a section
  51. };
  52. }
  53. };
  54. });
  55. CodeMirror.defineMIME("text/x-cisco-config", "cfg");
  56. });