Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
5 lars 1
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2
// Distributed under an MIT license: http://codemirror.net/LICENSE
3
 
4
(function(mod) {
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
6
    mod(require("../../lib/codemirror"));
7
  else if (typeof define == "function" && define.amd) // AMD
8
    define(["../../lib/codemirror"], mod);
9
  else // Plain browser env
10
    mod(CodeMirror);
11
})(function(CodeMirror) {
12
"use strict";
13
 
14
CodeMirror.defineMode("rpm-changes", function() {
15
  var headerSeperator = /^-+$/;
16
  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} - /;
17
  var simpleEmail = /^[\w+.-]+@[\w.-]+/;
18
 
19
  return {
20
    token: function(stream) {
21
      if (stream.sol()) {
22
        if (stream.match(headerSeperator)) { return 'tag'; }
23
        if (stream.match(headerLine)) { return 'tag'; }
24
      }
25
      if (stream.match(simpleEmail)) { return 'string'; }
26
      stream.next();
27
      return null;
28
    }
29
  };
30
});
31
 
32
CodeMirror.defineMIME("text/x-rpm-changes", "rpm-changes");
33
 
34
// Quick and dirty spec file highlighting
35
 
36
CodeMirror.defineMode("rpm-spec", function() {
37
  var arch = /^(i386|i586|i686|x86_64|ppc64|ppc|ia64|s390x|s390|sparc64|sparcv9|sparc|noarch|alphaev6|alpha|hppa|mipsel)/;
38
 
39
  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):/;
40
  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)/;
41
  var control_flow_complex = /^%(ifnarch|ifarch|if)/; // rpm control flow macros
42
  var control_flow_simple = /^%(else|endif)/; // rpm control flow macros
43
  var operators = /^(\!|\?|\<\=|\<|\>\=|\>|\=\=|\&\&|\|\|)/; // operators in control flow macros
44
 
45
  return {
46
    startState: function () {
47
        return {
48
          controlFlow: false,
49
          macroParameters: false,
50
          section: false
51
        };
52
    },
53
    token: function (stream, state) {
54
      var ch = stream.peek();
55
      if (ch == "#") { stream.skipToEnd(); return "comment"; }
56
 
57
      if (stream.sol()) {
58
        if (stream.match(preamble)) { return "preamble"; }
59
        if (stream.match(section)) { return "section"; }
60
      }
61
 
62
      if (stream.match(/^\$\w+/)) { return "def"; } // Variables like '$RPM_BUILD_ROOT'
63
      if (stream.match(/^\$\{\w+\}/)) { return "def"; } // Variables like '${RPM_BUILD_ROOT}'
64
 
65
      if (stream.match(control_flow_simple)) { return "keyword"; }
66
      if (stream.match(control_flow_complex)) {
67
        state.controlFlow = true;
68
        return "keyword";
69
      }
70
      if (state.controlFlow) {
71
        if (stream.match(operators)) { return "operator"; }
72
        if (stream.match(/^(\d+)/)) { return "number"; }
73
        if (stream.eol()) { state.controlFlow = false; }
74
      }
75
 
76
      if (stream.match(arch)) { return "number"; }
77
 
78
      // Macros like '%make_install' or '%attr(0775,root,root)'
79
      if (stream.match(/^%[\w]+/)) {
80
        if (stream.match(/^\(/)) { state.macroParameters = true; }
81
        return "macro";
82
      }
83
      if (state.macroParameters) {
84
        if (stream.match(/^\d+/)) { return "number";}
85
        if (stream.match(/^\)/)) {
86
          state.macroParameters = false;
87
          return "macro";
88
        }
89
      }
90
      if (stream.match(/^%\{\??[\w \-]+\}/)) { return "macro"; } // Macros like '%{defined fedora}'
91
 
92
      //TODO: Include bash script sub-parser (CodeMirror supports that)
93
      stream.next();
94
      return null;
95
    }
96
  };
97
});
98
 
99
CodeMirror.defineMIME("text/x-rpm-spec", "rpm-spec");
100
 
101
});