1 |
|
2 |
|
3 |
|
4 | (function(mod) {
|
5 | if (typeof exports == "object" && typeof module == "object")
|
6 | mod(require("../../lib/codemirror"));
|
7 | else if (typeof define == "function" && define.amd)
|
8 | define(["../../lib/codemirror"], mod);
|
9 | else
|
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 |
|
35 |
|
36 | CodeMirror.defineMode("rpm-spec", function() {
|
37 | var arch = /^(i386|i586|i686|x86_64|ppc64le|ppc64|ppc|ia64|s390x|s390|sparc64|sparcv9|sparc|noarch|alphaev6|alpha|hppa|mipsel)/;
|
38 |
|
39 | var preamble = /^[a-zA-Z0-9()]+:/;
|
40 | var section = /^%(debug_package|package|description|prep|build|install|files|clean|changelog|preinstall|preun|postinstall|postun|pretrans|posttrans|pre|post|triggerin|triggerun|verifyscript|check|triggerpostun|triggerprein|trigger)/;
|
41 | var control_flow_complex = /^%(ifnarch|ifarch|if)/;
|
42 | var control_flow_simple = /^%(else|endif)/;
|
43 | var operators = /^(\!|\?|\<\=|\<|\>\=|\>|\=\=|\&\&|\|\|)/;
|
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 "header"; }
|
59 | if (stream.match(section)) { return "atom"; }
|
60 | }
|
61 |
|
62 | if (stream.match(/^\$\w+/)) { return "def"; }
|
63 | if (stream.match(/^\$\{\w+\}/)) { return "def"; }
|
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)) {
|
77 | if (stream.eol()) { state.controlFlow = false; }
|
78 | return "number";
|
79 | }
|
80 |
|
81 |
|
82 | if (stream.match(/^%[\w]+/)) {
|
83 | if (stream.match(/^\(/)) { state.macroParameters = true; }
|
84 | return "keyword";
|
85 | }
|
86 | if (state.macroParameters) {
|
87 | if (stream.match(/^\d+/)) { return "number";}
|
88 | if (stream.match(/^\)/)) {
|
89 | state.macroParameters = false;
|
90 | return "keyword";
|
91 | }
|
92 | }
|
93 |
|
94 |
|
95 | if (stream.match(/^%\{\??[\w \-\:\!]+\}/)) {
|
96 | if (stream.eol()) { state.controlFlow = false; }
|
97 | return "def";
|
98 | }
|
99 |
|
100 |
|
101 | stream.next();
|
102 | return null;
|
103 | }
|
104 | };
|
105 | });
|
106 |
|
107 | CodeMirror.defineMIME("text/x-rpm-spec", "rpm-spec");
|
108 |
|
109 | });
|