~ubuntu-branches/ubuntu/utopic/codemirror-js/utopic

« back to all changes in this revision

Viewing changes to mode/rpm/spec/spec.js

  • Committer: Package Import Robot
  • Author(s): David Paleino
  • Date: 2012-04-12 12:25:28 UTC
  • Revision ID: package-import@ubuntu.com-20120412122528-8xp5a8frj4h1d3ee
Tags: upstream-2.23
ImportĀ upstreamĀ versionĀ 2.23

Show diffs side-by-side

added added

removed removed

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