LaravelTest
109 строк · 3.7 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("rpm-changes", function() {15var headerSeparator = /^-+$/;16var 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} - /;17var simpleEmail = /^[\w+.-]+@[\w.-]+/;18
19return {20token: function(stream) {21if (stream.sol()) {22if (stream.match(headerSeparator)) { return 'tag'; }23if (stream.match(headerLine)) { return 'tag'; }24}25if (stream.match(simpleEmail)) { return 'string'; }26stream.next();27return null;28}29};30});31
32CodeMirror.defineMIME("text/x-rpm-changes", "rpm-changes");33
34// Quick and dirty spec file highlighting
35
36CodeMirror.defineMode("rpm-spec", function() {37var arch = /^(i386|i586|i686|x86_64|ppc64le|ppc64|ppc|ia64|s390x|s390|sparc64|sparcv9|sparc|noarch|alphaev6|alpha|hppa|mipsel)/;38
39var preamble = /^[a-zA-Z0-9()]+:/;40var 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)/;41var control_flow_complex = /^%(ifnarch|ifarch|if)/; // rpm control flow macros42var control_flow_simple = /^%(else|endif)/; // rpm control flow macros43var operators = /^(\!|\?|\<\=|\<|\>\=|\>|\=\=|\&\&|\|\|)/; // operators in control flow macros44
45return {46startState: function () {47return {48controlFlow: false,49macroParameters: false,50section: false51};52},53token: function (stream, state) {54var ch = stream.peek();55if (ch == "#") { stream.skipToEnd(); return "comment"; }56
57if (stream.sol()) {58if (stream.match(preamble)) { return "header"; }59if (stream.match(section)) { return "atom"; }60}61
62if (stream.match(/^\$\w+/)) { return "def"; } // Variables like '$RPM_BUILD_ROOT'63if (stream.match(/^\$\{\w+\}/)) { return "def"; } // Variables like '${RPM_BUILD_ROOT}'64
65if (stream.match(control_flow_simple)) { return "keyword"; }66if (stream.match(control_flow_complex)) {67state.controlFlow = true;68return "keyword";69}70if (state.controlFlow) {71if (stream.match(operators)) { return "operator"; }72if (stream.match(/^(\d+)/)) { return "number"; }73if (stream.eol()) { state.controlFlow = false; }74}75
76if (stream.match(arch)) {77if (stream.eol()) { state.controlFlow = false; }78return "number";79}80
81// Macros like '%make_install' or '%attr(0775,root,root)'82if (stream.match(/^%[\w]+/)) {83if (stream.match('(')) { state.macroParameters = true; }84return "keyword";85}86if (state.macroParameters) {87if (stream.match(/^\d+/)) { return "number";}88if (stream.match(')')) {89state.macroParameters = false;90return "keyword";91}92}93
94// Macros like '%{defined fedora}'95if (stream.match(/^%\{\??[\w \-\:\!]+\}/)) {96if (stream.eol()) { state.controlFlow = false; }97return "def";98}99
100//TODO: Include bash script sub-parser (CodeMirror supports that)101stream.next();102return null;103}104};105});106
107CodeMirror.defineMIME("text/x-rpm-spec", "rpm-spec");108
109});110