1
// Quick and dirty spec file highlighting
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)/;
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
13
startState: function () {
16
macroParameters: false,
20
token: function (stream, state) {
21
var ch = stream.peek();
22
if (ch == "#") { stream.skipToEnd(); return "comment"; }
25
if (stream.match(preamble)) { return "preamble"; }
26
if (stream.match(section)) { return "section"; }
29
if (stream.match(/^\$\w+/)) { return "def"; } // Variables like '$RPM_BUILD_ROOT'
30
if (stream.match(/^\$\{\w+\}/)) { return "def"; } // Variables like '${RPM_BUILD_ROOT}'
32
if (stream.match(control_flow_simple)) { return "keyword"; }
33
if (stream.match(control_flow_complex)) {
34
state.controlFlow = true;
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; }
43
if (stream.match(arch)) { return "number"; }
45
// Macros like '%make_install' or '%attr(0775,root,root)'
46
if (stream.match(/^%[\w]+/)) {
47
if (stream.match(/^\(/)) { state.macroParameters = true; }
50
if (state.macroParameters) {
51
if (stream.match(/^\d+/)) { return "number";}
52
if (stream.match(/^\)/)) {
53
state.macroParameters = false;
57
if (stream.match(/^%\{\??[\w \-]+\}/)) { return "macro"; } // Macros like '%{defined fedora}'
59
//TODO: Include bash script sub-parser (CodeMirror supports that)
66
CodeMirror.defineMIME("text/x-rpm-spec", "spec");