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

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

Issue 22638008: DevTools: Use CodeMirror modes instead of highlight tokenizers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: address comments Created 7 years, 4 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/cmdevtools.css ('k') | Source/devtools/front_end/externs.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 (function(window) {
2 window.CodeMirror = {};
3
4 function splitLines(string){ return string.split(/\r?\n|\r/); };
5
6 function StringStream(string) {
7 this.pos = this.start = 0;
8 this.string = string;
9 }
10 StringStream.prototype = {
11 eol: function() {return this.pos >= this.string.length;},
12 sol: function() {return this.pos == 0;},
13 peek: function() {return this.string.charAt(this.pos) || null;},
14 next: function() {
15 if (this.pos < this.string.length)
16 return this.string.charAt(this.pos++);
17 },
18 eat: function(match) {
19 var ch = this.string.charAt(this.pos);
20 if (typeof match == "string") var ok = ch == match;
21 else var ok = ch && (match.test ? match.test(ch) : match(ch));
22 if (ok) {++this.pos; return ch;}
23 },
24 eatWhile: function(match) {
25 var start = this.pos;
26 while (this.eat(match)){}
27 return this.pos > start;
28 },
29 eatSpace: function() {
30 var start = this.pos;
31 while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
32 return this.pos > start;
33 },
34 skipToEnd: function() {this.pos = this.string.length;},
35 skipTo: function(ch) {
36 var found = this.string.indexOf(ch, this.pos);
37 if (found > -1) {this.pos = found; return true;}
38 },
39 backUp: function(n) {this.pos -= n;},
40 column: function() {return this.start;},
41 indentation: function() {return 0;},
42 match: function(pattern, consume, caseInsensitive) {
43 if (typeof pattern == "string") {
44 var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
45 var substr = this.string.substr(this.pos, pattern.length);
46 if (cased(substr) == cased(pattern)) {
47 if (consume !== false) this.pos += pattern.length;
48 return true;
49 }
50 } else {
51 var match = this.string.slice(this.pos).match(pattern);
52 if (match && match.index > 0) return null;
53 if (match && consume !== false) this.pos += match[0].length;
54 return match;
55 }
56 },
57 current: function(){return this.string.slice(this.start, this.pos);}
58 };
59 CodeMirror.StringStream = StringStream;
60
61 CodeMirror.startState = function (mode, a1, a2) {
62 return mode.startState ? mode.startState(a1, a2) : true;
63 };
64
65 var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
66 CodeMirror.defineMode = function (name, mode) { modes[name] = mode; };
67 CodeMirror.defineMIME = function (mime, spec) { mimeModes[mime] = spec; };
68 CodeMirror.defineMode("null", function() {
69 return {token: function(stream) {stream.skipToEnd();}};
70 });
71 CodeMirror.defineMIME("text/plain", "null");
72 CodeMirror.getMode = function (options, spec) {
73 if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
74 spec = mimeModes[spec];
75 if (typeof spec == "string")
76 var mname = spec, config = {};
77 else if (spec != null)
78 var mname = spec.name, config = spec;
79 var mfactory = modes[mname];
80 if (!mfactory) throw new Error("Unknown mode: " + spec);
81 return mfactory(options, config || {});
82 };
83 }(this));
OLDNEW
« no previous file with comments | « Source/devtools/front_end/cm/cmdevtools.css ('k') | Source/devtools/front_end/externs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698