diff options
author | Jose Antonio Marquez | 2012-02-15 20:37:48 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-02-15 20:37:48 -0800 |
commit | 89b5e793ea88ef235b54b6e1d1c379698d3e612b (patch) | |
tree | 4d29118f35df77ca6b423119a4ff61694a442cbf /imports/codemirror/mode/rpm/spec/spec.js | |
parent | 9d2c2a80483415d7560b00cda5519153db23e241 (diff) | |
parent | d366c0bd1af6471511217ed574083e15059519b5 (diff) | |
download | ninja-89b5e793ea88ef235b54b6e1d1c379698d3e612b.tar.gz |
Merge branch 'refs/heads/NinjaInternal' into Color
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"); | ||