aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/rpm/spec/spec.js
diff options
context:
space:
mode:
authorPushkar Joshi2012-02-24 12:08:49 -0800
committerPushkar Joshi2012-02-24 12:08:49 -0800
commit03ca7a5ed13c25faaa9100bb666e062fd15335e6 (patch)
treec51112223ceb9121cd595a60335eb2795215590f /imports/codemirror/mode/rpm/spec/spec.js
parentfcb12cc09eb3cd3b42bd215877ba18f449275b75 (diff)
parent053fc63a2950c7a5ee4ebf98033b64d474a3c46e (diff)
downloadninja-03ca7a5ed13c25faaa9100bb666e062fd15335e6.tar.gz
Merge branch 'pentool' into brushtool
Conflicts: imports/codemirror/mode/scheme/scheme.js js/tools/BrushTool.js
Diffstat (limited to 'imports/codemirror/mode/rpm/spec/spec.js')
-rwxr-xr-ximports/codemirror/mode/rpm/spec/spec.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/imports/codemirror/mode/rpm/spec/spec.js b/imports/codemirror/mode/rpm/spec/spec.js
new file mode 100755
index 00000000..3b5c08c9
--- /dev/null
+++ b/imports/codemirror/mode/rpm/spec/spec.js
@@ -0,0 +1,66 @@
1// Quick and dirty spec file highlighting
2
3CodeMirror.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
66CodeMirror.defineMIME("text/x-rpm-spec", "spec");