| OLD | NEW |
| 1 // CodeMirror, copyright (c) by Marijn Haverbeke and others | 1 // CodeMirror, copyright (c) by Marijn Haverbeke and others |
| 2 // Distributed under an MIT license: http://codemirror.net/LICENSE | 2 // Distributed under an MIT license: http://codemirror.net/LICENSE |
| 3 | 3 |
| 4 (function(mod) { | 4 (function(mod) { |
| 5 if (typeof exports == "object" && typeof module == "object") // CommonJS | 5 if (typeof exports == "object" && typeof module == "object") // CommonJS |
| 6 mod(require("../../lib/codemirror")); | 6 mod(require("../../lib/codemirror")); |
| 7 else if (typeof define == "function" && define.amd) // AMD | 7 else if (typeof define == "function" && define.amd) // AMD |
| 8 define(["../../lib/codemirror"], mod); | 8 define(["../../lib/codemirror"], mod); |
| 9 else // Plain browser env | 9 else // Plain browser env |
| 10 mod(CodeMirror); | 10 mod(CodeMirror); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 if (stream.eatSpace()) return null; | 39 if (stream.eatSpace()) return null; |
| 40 | 40 |
| 41 var sol = stream.sol(); | 41 var sol = stream.sol(); |
| 42 var ch = stream.next(); | 42 var ch = stream.next(); |
| 43 | 43 |
| 44 if (ch === '\\') { | 44 if (ch === '\\') { |
| 45 stream.next(); | 45 stream.next(); |
| 46 return null; | 46 return null; |
| 47 } | 47 } |
| 48 if (ch === '\'' || ch === '"' || ch === '`') { | 48 if (ch === '\'' || ch === '"' || ch === '`') { |
| 49 state.tokens.unshift(tokenString(ch)); | 49 state.tokens.unshift(tokenString(ch, ch === "`" ? "quote" : "string")); |
| 50 return tokenize(stream, state); | 50 return tokenize(stream, state); |
| 51 } | 51 } |
| 52 if (ch === '#') { | 52 if (ch === '#') { |
| 53 if (sol && stream.eat('!')) { | 53 if (sol && stream.eat('!')) { |
| 54 stream.skipToEnd(); | 54 stream.skipToEnd(); |
| 55 return 'meta'; // 'comment'? | 55 return 'meta'; // 'comment'? |
| 56 } | 56 } |
| 57 stream.skipToEnd(); | 57 stream.skipToEnd(); |
| 58 return 'comment'; | 58 return 'comment'; |
| 59 } | 59 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 74 if(stream.eol() || !/\w/.test(stream.peek())) { | 74 if(stream.eol() || !/\w/.test(stream.peek())) { |
| 75 return 'number'; | 75 return 'number'; |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 stream.eatWhile(/[\w-]/); | 78 stream.eatWhile(/[\w-]/); |
| 79 var cur = stream.current(); | 79 var cur = stream.current(); |
| 80 if (stream.peek() === '=' && /\w+/.test(cur)) return 'def'; | 80 if (stream.peek() === '=' && /\w+/.test(cur)) return 'def'; |
| 81 return words.hasOwnProperty(cur) ? words[cur] : null; | 81 return words.hasOwnProperty(cur) ? words[cur] : null; |
| 82 } | 82 } |
| 83 | 83 |
| 84 function tokenString(quote) { | 84 function tokenString(quote, style) { |
| 85 var close = quote == "(" ? ")" : quote |
| 85 return function(stream, state) { | 86 return function(stream, state) { |
| 86 var next, end = false, escaped = false; | 87 var next, end = false, escaped = false; |
| 87 while ((next = stream.next()) != null) { | 88 while ((next = stream.next()) != null) { |
| 88 if (next === quote && !escaped) { | 89 if (next === close && !escaped) { |
| 89 end = true; | 90 end = true; |
| 90 break; | 91 break; |
| 91 } | 92 } |
| 92 if (next === '$' && !escaped && quote !== '\'') { | 93 if (next === '$' && !escaped && quote !== "'") { |
| 93 escaped = true; | 94 escaped = true; |
| 94 stream.backUp(1); | 95 stream.backUp(1); |
| 95 state.tokens.unshift(tokenDollar); | 96 state.tokens.unshift(tokenDollar); |
| 96 break; | 97 break; |
| 97 } | 98 } |
| 99 if (!escaped && next === "(" && quote === "(") { |
| 100 state.tokens.unshift(tokenString(quote, style)) |
| 101 return tokenize(stream, state) |
| 102 } |
| 98 escaped = !escaped && next === '\\'; | 103 escaped = !escaped && next === '\\'; |
| 99 } | 104 } |
| 100 if (end || !escaped) { | 105 if (end || !escaped) state.tokens.shift(); |
| 101 state.tokens.shift(); | 106 return style; |
| 102 } | |
| 103 return (quote === '`' || quote === ')' ? 'quote' : 'string'); | |
| 104 }; | 107 }; |
| 105 }; | 108 }; |
| 106 | 109 |
| 107 var tokenDollar = function(stream, state) { | 110 var tokenDollar = function(stream, state) { |
| 108 if (state.tokens.length > 1) stream.eat('$'); | 111 if (state.tokens.length > 1) stream.eat('$'); |
| 109 var ch = stream.next(), hungry = /\w/; | 112 var ch = stream.next(), hungry = /\w/; |
| 110 if (ch === '{') hungry = /[^}]/; | 113 if (ch === '{') hungry = /[^}]/; |
| 111 if (ch === '(') { | 114 if (/['"(]/.test(ch)) { |
| 112 state.tokens[0] = tokenString(')'); | 115 state.tokens[0] = tokenString(ch, ch == "(" ? "quote" : "string"); |
| 113 return tokenize(stream, state); | 116 return tokenize(stream, state); |
| 114 } | 117 } |
| 115 if (!/\d/.test(ch)) { | 118 if (!/\d/.test(ch)) { |
| 116 stream.eatWhile(hungry); | 119 stream.eatWhile(hungry); |
| 117 stream.eat('}'); | 120 stream.eat('}'); |
| 118 } | 121 } |
| 119 state.tokens.shift(); | 122 state.tokens.shift(); |
| 120 return 'def'; | 123 return 'def'; |
| 121 }; | 124 }; |
| 122 | 125 |
| 123 function tokenize(stream, state) { | 126 function tokenize(stream, state) { |
| 124 return (state.tokens[0] || tokenBase) (stream, state); | 127 return (state.tokens[0] || tokenBase) (stream, state); |
| 125 }; | 128 }; |
| 126 | 129 |
| 127 return { | 130 return { |
| 128 startState: function() {return {tokens:[]};}, | 131 startState: function() {return {tokens:[]};}, |
| 129 token: function(stream, state) { | 132 token: function(stream, state) { |
| 130 return tokenize(stream, state); | 133 return tokenize(stream, state); |
| 131 }, | 134 }, |
| 135 closeBrackets: "()[]{}''\"\"``", |
| 132 lineComment: '#', | 136 lineComment: '#', |
| 133 fold: "brace" | 137 fold: "brace" |
| 134 }; | 138 }; |
| 135 }); | 139 }); |
| 136 | 140 |
| 137 CodeMirror.defineMIME('text/x-sh', 'shell'); | 141 CodeMirror.defineMIME('text/x-sh', 'shell'); |
| 138 | 142 |
| 139 }); | 143 }); |
| OLD | NEW |