| 1 |
var headerSeparator = /^-+$/; |
| 2 |
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} - /; |
| 3 |
var simpleEmail = /^[\w+.-]+@[\w.-]+/; |
| 4 |
|
| 5 |
export const rpmChanges = { |
| 6 |
name: "rpmchanges", |
| 7 |
token: function(stream) { |
| 8 |
if (stream.sol()) { |
| 9 |
if (stream.match(headerSeparator)) { return 'tag'; } |
| 10 |
if (stream.match(headerLine)) { return 'tag'; } |
| 11 |
} |
| 12 |
if (stream.match(simpleEmail)) { return 'string'; } |
| 13 |
stream.next(); |
| 14 |
return null; |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
// Quick and dirty spec file highlighting |
| 19 |
|
| 20 |
var arch = /^(i386|i586|i686|x86_64|ppc64le|ppc64|ppc|ia64|s390x|s390|sparc64|sparcv9|sparc|noarch|alphaev6|alpha|hppa|mipsel)/; |
| 21 |
|
| 22 |
var preamble = /^[a-zA-Z0-9()]+:/; |
| 23 |
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)/; |
| 24 |
var control_flow_complex = /^%(ifnarch|ifarch|if)/; // rpm control flow macros |
| 25 |
var control_flow_simple = /^%(else|endif)/; // rpm control flow macros |
| 26 |
var operators = /^(\!|\?|\<\=|\<|\>\=|\>|\=\=|\&\&|\|\|)/; // operators in control flow macros |
| 27 |
|
| 28 |
export const rpmSpec = { |
| 29 |
name: "rpmspec", |
| 30 |
startState: function () { |
| 31 |
return { |
| 32 |
controlFlow: false, |
| 33 |
macroParameters: false, |
| 34 |
section: false |
| 35 |
}; |
| 36 |
}, |
| 37 |
token: function (stream, state) { |
| 38 |
var ch = stream.peek(); |
| 39 |
if (ch == "#") { stream.skipToEnd(); return "comment"; } |
| 40 |
|
| 41 |
if (stream.sol()) { |
| 42 |
if (stream.match(preamble)) { return "header"; } |
| 43 |
if (stream.match(section)) { return "atom"; } |
| 44 |
} |
| 45 |
|
| 46 |
if (stream.match(/^\$\w+/)) { return "def"; } // Variables like '$RPM_BUILD_ROOT' |
| 47 |
if (stream.match(/^\$\{\w+\}/)) { return "def"; } // Variables like '${RPM_BUILD_ROOT}' |
| 48 |
|
| 49 |
if (stream.match(control_flow_simple)) { return "keyword"; } |
| 50 |
if (stream.match(control_flow_complex)) { |
| 51 |
state.controlFlow = true; |
| 52 |
return "keyword"; |
| 53 |
} |
| 54 |
if (state.controlFlow) { |
| 55 |
if (stream.match(operators)) { return "operator"; } |
| 56 |
if (stream.match(/^(\d+)/)) { return "number"; } |
| 57 |
if (stream.eol()) { state.controlFlow = false; } |
| 58 |
} |
| 59 |
|
| 60 |
if (stream.match(arch)) { |
| 61 |
if (stream.eol()) { state.controlFlow = false; } |
| 62 |
return "number"; |
| 63 |
} |
| 64 |
|
| 65 |
// Macros like '%make_install' or '%attr(0775,root,root)' |
| 66 |
if (stream.match(/^%[\w]+/)) { |
| 67 |
if (stream.match('(')) { state.macroParameters = true; } |
| 68 |
return "keyword"; |
| 69 |
} |
| 70 |
if (state.macroParameters) { |
| 71 |
if (stream.match(/^\d+/)) { return "number";} |
| 72 |
if (stream.match(')')) { |
| 73 |
state.macroParameters = false; |
| 74 |
return "keyword"; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
// Macros like '%{defined fedora}' |
| 79 |
if (stream.match(/^%\{\??[\w \-\:\!]+\}/)) { |
| 80 |
if (stream.eol()) { state.controlFlow = false; } |
| 81 |
return "def"; |
| 82 |
} |
| 83 |
|
| 84 |
stream.next(); |
| 85 |
return null; |
| 86 |
} |
| 87 |
}; |
| 88 |
|