spec.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Quick and dirty spec file highlighting
  2. CodeMirror.defineMode("spec", function() {
  3. var arch = /^(i386|i586|i686|x86_64|ppc64|ppc|ia64|s390x|s390|sparc64|sparcv9|sparc|noarch|alphaev6|alpha|hppa|mipsel)/;
  4. 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):/;
  5. var section = /^%(debug_package|package|description|prep|build|install|files|clean|changelog|preun|postun|pre|post|triggerin|triggerun|pretrans|posttrans|verifyscript|check|triggerpostun|triggerprein|trigger)/;
  6. var control_flow_complex = /^%(ifnarch|ifarch|if)/; // rpm control flow macros
  7. var control_flow_simple = /^%(else|endif)/; // rpm control flow macros
  8. var operators = /^(\!|\?|\<\=|\<|\>\=|\>|\=\=|\&\&|\|\|)/; // operators in control flow macros
  9. return {
  10. startState: function () {
  11. return {
  12. controlFlow: false,
  13. macroParameters: false,
  14. section: false
  15. };
  16. },
  17. token: function (stream, state) {
  18. var ch = stream.peek();
  19. if (ch == "#") { stream.skipToEnd(); return "comment"; }
  20. if (stream.sol()) {
  21. if (stream.match(preamble)) { return "preamble"; }
  22. if (stream.match(section)) { return "section"; }
  23. }
  24. if (stream.match(/^\$\w+/)) { return "def"; } // Variables like '$RPM_BUILD_ROOT'
  25. if (stream.match(/^\$\{\w+\}/)) { return "def"; } // Variables like '${RPM_BUILD_ROOT}'
  26. if (stream.match(control_flow_simple)) { return "keyword"; }
  27. if (stream.match(control_flow_complex)) {
  28. state.controlFlow = true;
  29. return "keyword";
  30. }
  31. if (state.controlFlow) {
  32. if (stream.match(operators)) { return "operator"; }
  33. if (stream.match(/^(\d+)/)) { return "number"; }
  34. if (stream.eol()) { state.controlFlow = false; }
  35. }
  36. if (stream.match(arch)) { return "number"; }
  37. // Macros like '%make_install' or '%attr(0775,root,root)'
  38. if (stream.match(/^%[\w]+/)) {
  39. if (stream.match(/^\(/)) { state.macroParameters = true; }
  40. return "macro";
  41. }
  42. if (state.macroParameters) {
  43. if (stream.match(/^\d+/)) { return "number";}
  44. if (stream.match(/^\)/)) {
  45. state.macroParameters = false;
  46. return "macro";
  47. }
  48. }
  49. if (stream.match(/^%\{\??[\w \-]+\}/)) { return "macro"; } // Macros like '%{defined fedora}'
  50. //TODO: Include bash script sub-parser (CodeMirror supports that)
  51. stream.next();
  52. return null;
  53. }
  54. };
  55. });
  56. CodeMirror.defineMIME("text/x-rpm-spec", "spec");