LaravelTest
168 строк · 5.3 Кб
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('shell', function() {15
16var words = {};17function define(style, dict) {18for(var i = 0; i < dict.length; i++) {19words[dict[i]] = style;20}21};22
23var commonAtoms = ["true", "false"];24var commonKeywords = ["if", "then", "do", "else", "elif", "while", "until", "for", "in", "esac", "fi",25"fin", "fil", "done", "exit", "set", "unset", "export", "function"];26var commonCommands = ["ab", "awk", "bash", "beep", "cat", "cc", "cd", "chown", "chmod", "chroot", "clear",27"cp", "curl", "cut", "diff", "echo", "find", "gawk", "gcc", "get", "git", "grep", "hg", "kill", "killall",28"ln", "ls", "make", "mkdir", "openssl", "mv", "nc", "nl", "node", "npm", "ping", "ps", "restart", "rm",29"rmdir", "sed", "service", "sh", "shopt", "shred", "source", "sort", "sleep", "ssh", "start", "stop",30"su", "sudo", "svn", "tee", "telnet", "top", "touch", "vi", "vim", "wall", "wc", "wget", "who", "write",31"yes", "zsh"];32
33CodeMirror.registerHelper("hintWords", "shell", commonAtoms.concat(commonKeywords, commonCommands));34
35define('atom', commonAtoms);36define('keyword', commonKeywords);37define('builtin', commonCommands);38
39function tokenBase(stream, state) {40if (stream.eatSpace()) return null;41
42var sol = stream.sol();43var ch = stream.next();44
45if (ch === '\\') {46stream.next();47return null;48}49if (ch === '\'' || ch === '"' || ch === '`') {50state.tokens.unshift(tokenString(ch, ch === "`" ? "quote" : "string"));51return tokenize(stream, state);52}53if (ch === '#') {54if (sol && stream.eat('!')) {55stream.skipToEnd();56return 'meta'; // 'comment'?57}58stream.skipToEnd();59return 'comment';60}61if (ch === '$') {62state.tokens.unshift(tokenDollar);63return tokenize(stream, state);64}65if (ch === '+' || ch === '=') {66return 'operator';67}68if (ch === '-') {69stream.eat('-');70stream.eatWhile(/\w/);71return 'attribute';72}73if (ch == "<") {74if (stream.match("<<")) return "operator"75var heredoc = stream.match(/^<-?\s*['"]?([^'"]*)['"]?/)76if (heredoc) {77state.tokens.unshift(tokenHeredoc(heredoc[1]))78return 'string-2'79}80}81if (/\d/.test(ch)) {82stream.eatWhile(/\d/);83if(stream.eol() || !/\w/.test(stream.peek())) {84return 'number';85}86}87stream.eatWhile(/[\w-]/);88var cur = stream.current();89if (stream.peek() === '=' && /\w+/.test(cur)) return 'def';90return words.hasOwnProperty(cur) ? words[cur] : null;91}92
93function tokenString(quote, style) {94var close = quote == "(" ? ")" : quote == "{" ? "}" : quote95return function(stream, state) {96var next, escaped = false;97while ((next = stream.next()) != null) {98if (next === close && !escaped) {99state.tokens.shift();100break;101} else if (next === '$' && !escaped && quote !== "'" && stream.peek() != close) {102escaped = true;103stream.backUp(1);104state.tokens.unshift(tokenDollar);105break;106} else if (!escaped && quote !== close && next === quote) {107state.tokens.unshift(tokenString(quote, style))108return tokenize(stream, state)109} else if (!escaped && /['"]/.test(next) && !/['"]/.test(quote)) {110state.tokens.unshift(tokenStringStart(next, "string"));111stream.backUp(1);112break;113}114escaped = !escaped && next === '\\';115}116return style;117};118};119
120function tokenStringStart(quote, style) {121return function(stream, state) {122state.tokens[0] = tokenString(quote, style)123stream.next()124return tokenize(stream, state)125}126}127
128var tokenDollar = function(stream, state) {129if (state.tokens.length > 1) stream.eat('$');130var ch = stream.next()131if (/['"({]/.test(ch)) {132state.tokens[0] = tokenString(ch, ch == "(" ? "quote" : ch == "{" ? "def" : "string");133return tokenize(stream, state);134}135if (!/\d/.test(ch)) stream.eatWhile(/\w/);136state.tokens.shift();137return 'def';138};139
140function tokenHeredoc(delim) {141return function(stream, state) {142if (stream.sol() && stream.string == delim) state.tokens.shift()143stream.skipToEnd()144return "string-2"145}146}147
148function tokenize(stream, state) {149return (state.tokens[0] || tokenBase) (stream, state);150};151
152return {153startState: function() {return {tokens:[]};},154token: function(stream, state) {155return tokenize(stream, state);156},157closeBrackets: "()[]{}''\"\"``",158lineComment: '#',159fold: "brace"160};161});162
163CodeMirror.defineMIME('text/x-sh', 'shell');164// Apache uses a slightly different Media Type for Shell scripts
165// http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
166CodeMirror.defineMIME('application/x-sh', 'shell');167
168});169