rpm.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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("rpm-changes", function() {
  13. var headerSeperator = /^-+$/;
  14. var headerLine = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ?\d{1,2} \d{2}:\d{2}(:\d{2})? [A-Z]{3,4} \d{4} - /;
  15. var simpleEmail = /^[\w+.-]+@[\w.-]+/;
  16. return {
  17. token: function(stream) {
  18. if (stream.sol()) {
  19. if (stream.match(headerSeperator)) { return 'tag'; }
  20. if (stream.match(headerLine)) { return 'tag'; }
  21. }
  22. if (stream.match(simpleEmail)) { return 'string'; }
  23. stream.next();
  24. return null;
  25. }
  26. };
  27. });
  28. CodeMirror.defineMIME("text/x-rpm-changes", "rpm-changes");
  29. // Quick and dirty spec file highlighting
  30. CodeMirror.defineMode("rpm-spec", function() {
  31. var arch = /^(i386|i586|i686|x86_64|ppc64|ppc|ia64|s390x|s390|sparc64|sparcv9|sparc|noarch|alphaev6|alpha|hppa|mipsel)/;
  32. var preamble = /^(Name|Version|Release|License|Summary|Url|Group|Source|BuildArch|BuildRequires|BuildRoot|AutoReqProv|Provides|Requires(\(\w+\))?|Obsoletes|Conflicts|Recommends|Source\d*|Patch\d*|ExclusiveArch|NoSource|Supplements):/;
  33. var section = /^%(debug_package|package|description|prep|build|install|files|clean|changelog|preinstall|preun|postinstall|postun|pre|post|triggerin|triggerun|pretrans|posttrans|verifyscript|check|triggerpostun|triggerprein|trigger)/;
  34. var control_flow_complex = /^%(ifnarch|ifarch|if)/; // rpm control flow macros
  35. var control_flow_simple = /^%(else|endif)/; // rpm control flow macros
  36. var operators = /^(\!|\?|\<\=|\<|\>\=|\>|\=\=|\&\&|\|\|)/; // operators in control flow macros
  37. return {
  38. startState: function () {
  39. return {
  40. controlFlow: false,
  41. macroParameters: false,
  42. section: false
  43. };
  44. },
  45. token: function (stream, state) {
  46. var ch = stream.peek();
  47. if (ch == "#") { stream.skipToEnd(); return "comment"; }
  48. if (stream.sol()) {
  49. if (stream.match(preamble)) { return "preamble"; }
  50. if (stream.match(section)) { return "section"; }
  51. }
  52. if (stream.match(/^\$\w+/)) { return "def"; } // Variables like '$RPM_BUILD_ROOT'
  53. if (stream.match(/^\$\{\w+\}/)) { return "def"; } // Variables like '${RPM_BUILD_ROOT}'
  54. if (stream.match(control_flow_simple)) { return "keyword"; }
  55. if (stream.match(control_flow_complex)) {
  56. state.controlFlow = true;
  57. return "keyword";
  58. }
  59. if (state.controlFlow) {
  60. if (stream.match(operators)) { return "operator"; }
  61. if (stream.match(/^(\d+)/)) { return "number"; }
  62. if (stream.eol()) { state.controlFlow = false; }
  63. }
  64. if (stream.match(arch)) { return "number"; }
  65. // Macros like '%make_install' or '%attr(0775,root,root)'
  66. if (stream.match(/^%[\w]+/)) {
  67. if (stream.match(/^\(/)) { state.macroParameters = true; }
  68. return "macro";
  69. }
  70. if (state.macroParameters) {
  71. if (stream.match(/^\d+/)) { return "number";}
  72. if (stream.match(/^\)/)) {
  73. state.macroParameters = false;
  74. return "macro";
  75. }
  76. }
  77. if (stream.match(/^%\{\??[\w \-]+\}/)) { return "macro"; } // Macros like '%{defined fedora}'
  78. //TODO: Include bash script sub-parser (CodeMirror supports that)
  79. stream.next();
  80. return null;
  81. }
  82. };
  83. });
  84. CodeMirror.defineMIME("text/x-rpm-spec", "rpm-spec");
  85. });