Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1026)

Side by Side Diff: Source/devtools/front_end/cm/shell.js

Issue 354833004: DevTools: [CodeMirror] roll CodeMirror to version @e20d175 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: address comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/devtools/front_end/cm/python.js ('k') | Source/devtools/front_end/cm/xml.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 // Distributed under an MIT license: http://codemirror.net/LICENSE
3
4 (function(mod) {
5 if (typeof exports == "object" && typeof module == "object") // CommonJS
6 mod(require("../../lib/codemirror"));
7 else if (typeof define == "function" && define.amd) // AMD
8 define(["../../lib/codemirror"], mod);
9 else // Plain browser env
10 mod(CodeMirror);
11 })(function(CodeMirror) {
12 "use strict";
13
1 CodeMirror.defineMode('shell', function() { 14 CodeMirror.defineMode('shell', function() {
2 15
3 var words = {}; 16 var words = {};
4 function define(style, string) { 17 function define(style, string) {
5 var split = string.split(' '); 18 var split = string.split(' ');
6 for(var i = 0; i < split.length; i++) { 19 for(var i = 0; i < split.length; i++) {
7 words[split[i]] = style; 20 words[split[i]] = style;
8 } 21 }
9 }; 22 };
10 23
11 // Atoms 24 // Atoms
12 define('atom', 'true false'); 25 define('atom', 'true false');
13 26
14 // Keywords 27 // Keywords
15 define('keyword', 'if then do else elif while until for in esac fi fin ' + 28 define('keyword', 'if then do else elif while until for in esac fi fin ' +
16 'fil done exit set unset export function'); 29 'fil done exit set unset export function');
17 30
18 // Commands 31 // Commands
19 define('builtin', 'ab awk bash beep cat cc cd chown chmod chroot clear cp ' + 32 define('builtin', 'ab awk bash beep cat cc cd chown chmod chroot clear cp ' +
20 'curl cut diff echo find gawk gcc get git grep kill killall ln ls make ' + 33 'curl cut diff echo find gawk gcc get git grep kill killall ln ls make ' +
21 'mkdir openssl mv nc node npm ping ps restart rm rmdir sed service sh ' + 34 'mkdir openssl mv nc node npm ping ps restart rm rmdir sed service sh ' +
22 'shopt shred source sort sleep ssh start stop su sudo tee telnet top ' + 35 'shopt shred source sort sleep ssh start stop su sudo tee telnet top ' +
23 'touch vi vim wall wc wget who write yes zsh'); 36 'touch vi vim wall wc wget who write yes zsh');
24 37
25 function tokenBase(stream, state) { 38 function tokenBase(stream, state) {
39 if (stream.eatSpace()) return null;
26 40
27 var sol = stream.sol(); 41 var sol = stream.sol();
28 var ch = stream.next(); 42 var ch = stream.next();
29 43
44 if (ch === '\\') {
45 stream.next();
46 return null;
47 }
30 if (ch === '\'' || ch === '"' || ch === '`') { 48 if (ch === '\'' || ch === '"' || ch === '`') {
31 state.tokens.unshift(tokenString(ch)); 49 state.tokens.unshift(tokenString(ch));
32 return tokenize(stream, state); 50 return tokenize(stream, state);
33 } 51 }
34 if (ch === '#') { 52 if (ch === '#') {
35 if (sol && stream.eat('!')) { 53 if (sol && stream.eat('!')) {
36 stream.skipToEnd(); 54 stream.skipToEnd();
37 return 'meta'; // 'comment'? 55 return 'meta'; // 'comment'?
38 } 56 }
39 stream.skipToEnd(); 57 stream.skipToEnd();
40 return 'comment'; 58 return 'comment';
41 } 59 }
42 if (ch === '$') { 60 if (ch === '$') {
43 state.tokens.unshift(tokenDollar); 61 state.tokens.unshift(tokenDollar);
44 return tokenize(stream, state); 62 return tokenize(stream, state);
45 } 63 }
46 if (ch === '+' || ch === '=') { 64 if (ch === '+' || ch === '=') {
47 return 'operator'; 65 return 'operator';
48 } 66 }
49 if (ch === '-') { 67 if (ch === '-') {
50 stream.eat('-'); 68 stream.eat('-');
51 stream.eatWhile(/\w/); 69 stream.eatWhile(/\w/);
52 return 'attribute'; 70 return 'attribute';
53 } 71 }
54 if (/\d/.test(ch)) { 72 if (/\d/.test(ch)) {
55 stream.eatWhile(/\d/); 73 stream.eatWhile(/\d/);
56 if(!/\w/.test(stream.peek())) { 74 if(stream.eol() || !/\w/.test(stream.peek())) {
57 return 'number'; 75 return 'number';
58 } 76 }
59 } 77 }
60 stream.eatWhile(/[\w-]/); 78 stream.eatWhile(/[\w-]/);
61 var cur = stream.current(); 79 var cur = stream.current();
62 if (stream.peek() === '=' && /\w+/.test(cur)) return 'def'; 80 if (stream.peek() === '=' && /\w+/.test(cur)) return 'def';
63 return words.hasOwnProperty(cur) ? words[cur] : null; 81 return words.hasOwnProperty(cur) ? words[cur] : null;
64 } 82 }
65 83
66 function tokenString(quote) { 84 function tokenString(quote) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return 'def'; 120 return 'def';
103 }; 121 };
104 122
105 function tokenize(stream, state) { 123 function tokenize(stream, state) {
106 return (state.tokens[0] || tokenBase) (stream, state); 124 return (state.tokens[0] || tokenBase) (stream, state);
107 }; 125 };
108 126
109 return { 127 return {
110 startState: function() {return {tokens:[]};}, 128 startState: function() {return {tokens:[]};},
111 token: function(stream, state) { 129 token: function(stream, state) {
112 if (stream.eatSpace()) return null;
113 return tokenize(stream, state); 130 return tokenize(stream, state);
114 } 131 }
115 }; 132 };
116 }); 133 });
117 134
118 CodeMirror.defineMIME('text/x-sh', 'shell'); 135 CodeMirror.defineMIME('text/x-sh', 'shell');
136
137 });
OLDNEW
« no previous file with comments | « Source/devtools/front_end/cm/python.js ('k') | Source/devtools/front_end/cm/xml.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698