diff options
author | Valerio Virgillito | 2012-02-15 17:04:39 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-15 17:04:39 -0800 |
commit | fe71cb9aa1700199c0089166ad54fc56eb760644 (patch) | |
tree | b0c7c24b1f45a079e1c09312ca716e3d35aecad4 /imports/codemirror/mode/rpm/spec/spec.js | |
parent | 747616980cad14f0b65fbcc7f497ed9680a39d29 (diff) | |
parent | d366c0bd1af6471511217ed574083e15059519b5 (diff) | |
download | ninja-fe71cb9aa1700199c0089166ad54fc56eb760644.tar.gz |
Merge branch 'refs/heads/master' into components
Diffstat (limited to 'imports/codemirror/mode/rpm/spec/spec.js')
-rwxr-xr-x | imports/codemirror/mode/rpm/spec/spec.js | 66 |
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 | |||
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"); | ||