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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/cm_modes/python.js

Issue 2772343006: DevTools: Roll CodeMirror to 5.25.1 (Closed)
Patch Set: stray space Created 3 years, 8 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
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 var hangingIndent = parserConf.hangingIndent || conf.indentUnit; 49 var hangingIndent = parserConf.hangingIndent || conf.indentUnit;
50 50
51 var myKeywords = commonKeywords, myBuiltins = commonBuiltins; 51 var myKeywords = commonKeywords, myBuiltins = commonBuiltins;
52 if (parserConf.extra_keywords != undefined) 52 if (parserConf.extra_keywords != undefined)
53 myKeywords = myKeywords.concat(parserConf.extra_keywords); 53 myKeywords = myKeywords.concat(parserConf.extra_keywords);
54 54
55 if (parserConf.extra_builtins != undefined) 55 if (parserConf.extra_builtins != undefined)
56 myBuiltins = myBuiltins.concat(parserConf.extra_builtins); 56 myBuiltins = myBuiltins.concat(parserConf.extra_builtins);
57 57
58 var py3 = parserConf.version && parseInt(parserConf.version, 10) == 3 58 var py3 = !(parserConf.version && Number(parserConf.version) < 3)
59 if (py3) { 59 if (py3) {
60 // since http://legacy.python.org/dev/peps/pep-0465/ @ is also an operator 60 // since http://legacy.python.org/dev/peps/pep-0465/ @ is also an operator
61 var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!@] /; 61 var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!@] /;
62 var identifiers = parserConf.identifiers|| /^[_A-Za-z\u00A1-\uFFFF][_A-Za- z0-9\u00A1-\uFFFF]*/; 62 var identifiers = parserConf.identifiers|| /^[_A-Za-z\u00A1-\uFFFF][_A-Za- z0-9\u00A1-\uFFFF]*/;
63 myKeywords = myKeywords.concat(["nonlocal", "False", "True", "None", "asyn c", "await"]); 63 myKeywords = myKeywords.concat(["nonlocal", "False", "True", "None", "asyn c", "await"]);
64 myBuiltins = myBuiltins.concat(["ascii", "bytes", "exec", "print"]); 64 myBuiltins = myBuiltins.concat(["ascii", "bytes", "exec", "print"]);
65 var stringPrefixes = new RegExp("^(([rbuf]|(br))?('{3}|\"{3}|['\"]))", "i" ); 65 var stringPrefixes = new RegExp("^(([rbuf]|(br))?('{3}|\"{3}|['\"]))", "i" );
66 } else { 66 } else {
67 var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!]/ ; 67 var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!]/ ;
68 var identifiers = parserConf.identifiers|| /^[_A-Za-z][_A-Za-z0-9]*/; 68 var identifiers = parserConf.identifiers|| /^[_A-Za-z][_A-Za-z0-9]*/;
69 myKeywords = myKeywords.concat(["exec", "print"]); 69 myKeywords = myKeywords.concat(["exec", "print"]);
70 myBuiltins = myBuiltins.concat(["apply", "basestring", "buffer", "cmp", "c oerce", "execfile", 70 myBuiltins = myBuiltins.concat(["apply", "basestring", "buffer", "cmp", "c oerce", "execfile",
71 "file", "intern", "long", "raw_input", "re duce", "reload", 71 "file", "intern", "long", "raw_input", "re duce", "reload",
72 "unichr", "unicode", "xrange", "False", "T rue", "None"]); 72 "unichr", "unicode", "xrange", "False", "T rue", "None"]);
73 var stringPrefixes = new RegExp("^(([rub]|(ur)|(br))?('{3}|\"{3}|['\"]))", "i"); 73 var stringPrefixes = new RegExp("^(([rubf]|(ur)|(br))?('{3}|\"{3}|['\"]))" , "i");
74 } 74 }
75 var keywords = wordRegexp(myKeywords); 75 var keywords = wordRegexp(myKeywords);
76 var builtins = wordRegexp(myBuiltins); 76 var builtins = wordRegexp(myBuiltins);
77 77
78 // tokenizers 78 // tokenizers
79 function tokenBase(stream, state) { 79 function tokenBase(stream, state) {
80 if (stream.sol()) state.indent = stream.indentation() 80 if (stream.sol()) state.indent = stream.indentation()
81 // Handle scope changes 81 // Handle scope changes
82 if (stream.sol() && top(state).type == "py") { 82 if (stream.sol() && top(state).type == "py") {
83 var scopeOffset = top(state).offset; 83 var scopeOffset = top(state).offset;
84 if (stream.eatSpace()) { 84 if (stream.eatSpace()) {
85 var lineOffset = stream.indentation(); 85 var lineOffset = stream.indentation();
86 if (lineOffset > scopeOffset) 86 if (lineOffset > scopeOffset)
87 pushPyScope(state); 87 pushPyScope(state);
88 else if (lineOffset < scopeOffset && dedent(stream, state)) 88 else if (lineOffset < scopeOffset && dedent(stream, state) && stream.p eek() != "#")
89 state.errorToken = true; 89 state.errorToken = true;
90 return null; 90 return null;
91 } else { 91 } else {
92 var style = tokenBaseInner(stream, state); 92 var style = tokenBaseInner(stream, state);
93 if (scopeOffset > 0 && dedent(stream, state)) 93 if (scopeOffset > 0 && dedent(stream, state))
94 style += " " + ERRORCLASS; 94 style += " " + ERRORCLASS;
95 return style; 95 return style;
96 } 96 }
97 } 97 }
98 return tokenBaseInner(stream, state); 98 return tokenBaseInner(stream, state);
99 } 99 }
100 100
101 function tokenBaseInner(stream, state) { 101 function tokenBaseInner(stream, state) {
102 if (stream.eatSpace()) return null; 102 if (stream.eatSpace()) return null;
103 103
104 var ch = stream.peek(); 104 var ch = stream.peek();
105 105
106 // Handle Comments 106 // Handle Comments
107 if (ch == "#") { 107 if (ch == "#") {
108 stream.skipToEnd(); 108 stream.skipToEnd();
109 return "comment"; 109 return "comment";
110 } 110 }
111 111
112 // Handle Number Literals 112 // Handle Number Literals
113 if (stream.match(/^[0-9\.]/, false)) { 113 if (stream.match(/^[0-9\.]/, false)) {
114 var floatLiteral = false; 114 var floatLiteral = false;
115 // Floats 115 // Floats
116 if (stream.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; } 116 if (stream.match(/^[\d_]*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; }
117 if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; } 117 if (stream.match(/^[\d_]+\.\d*/)) { floatLiteral = true; }
118 if (stream.match(/^\.\d+/)) { floatLiteral = true; } 118 if (stream.match(/^\.\d+/)) { floatLiteral = true; }
119 if (floatLiteral) { 119 if (floatLiteral) {
120 // Float literals may be "imaginary" 120 // Float literals may be "imaginary"
121 stream.eat(/J/i); 121 stream.eat(/J/i);
122 return "number"; 122 return "number";
123 } 123 }
124 // Integers 124 // Integers
125 var intLiteral = false; 125 var intLiteral = false;
126 // Hex 126 // Hex
127 if (stream.match(/^0x[0-9a-f]+/i)) intLiteral = true; 127 if (stream.match(/^0x[0-9a-f_]+/i)) intLiteral = true;
128 // Binary 128 // Binary
129 if (stream.match(/^0b[01]+/i)) intLiteral = true; 129 if (stream.match(/^0b[01_]+/i)) intLiteral = true;
130 // Octal 130 // Octal
131 if (stream.match(/^0o[0-7]+/i)) intLiteral = true; 131 if (stream.match(/^0o[0-7_]+/i)) intLiteral = true;
132 // Decimal 132 // Decimal
133 if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) { 133 if (stream.match(/^[1-9][\d_]*(e[\+\-]?[\d_]+)?/)) {
134 // Decimal literals may be "imaginary" 134 // Decimal literals may be "imaginary"
135 stream.eat(/J/i); 135 stream.eat(/J/i);
136 // TODO - Can you have imaginary longs? 136 // TODO - Can you have imaginary longs?
137 intLiteral = true; 137 intLiteral = true;
138 } 138 }
139 // Zero by itself with no other piece of number. 139 // Zero by itself with no other piece of number.
140 if (stream.match(/^0(?![\dx])/i)) intLiteral = true; 140 if (stream.match(/^0(?![\dx])/i)) intLiteral = true;
141 if (intLiteral) { 141 if (intLiteral) {
142 // Integer literals may be "long" 142 // Integer literals may be "long"
143 stream.eat(/L/i); 143 stream.eat(/L/i);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return "def"; 178 return "def";
179 return "variable"; 179 return "variable";
180 } 180 }
181 181
182 // Handle non-detected items 182 // Handle non-detected items
183 stream.next(); 183 stream.next();
184 return ERRORCLASS; 184 return ERRORCLASS;
185 } 185 }
186 186
187 function tokenStringFactory(delimiter) { 187 function tokenStringFactory(delimiter) {
188 while ("rub".indexOf(delimiter.charAt(0).toLowerCase()) >= 0) 188 while ("rubf".indexOf(delimiter.charAt(0).toLowerCase()) >= 0)
189 delimiter = delimiter.substr(1); 189 delimiter = delimiter.substr(1);
190 190
191 var singleline = delimiter.length == 1; 191 var singleline = delimiter.length == 1;
192 var OUTCLASS = "string"; 192 var OUTCLASS = "string";
193 193
194 function tokenString(stream, state) { 194 function tokenString(stream, state) {
195 while (!stream.eol()) { 195 while (!stream.eol()) {
196 stream.eatWhile(/[^'"\\]/); 196 stream.eatWhile(/[^'"\\]/);
197 if (stream.eat("\\")) { 197 if (stream.eat("\\")) {
198 stream.next(); 198 stream.next();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 var words = function(str) { return str.split(" "); }; 331 var words = function(str) { return str.split(" "); };
332 332
333 CodeMirror.defineMIME("text/x-cython", { 333 CodeMirror.defineMIME("text/x-cython", {
334 name: "python", 334 name: "python",
335 extra_keywords: words("by cdef cimport cpdef ctypedef enum except"+ 335 extra_keywords: words("by cdef cimport cpdef ctypedef enum except"+
336 "extern gil include nogil property public"+ 336 "extern gil include nogil property public"+
337 "readonly struct union DEF IF ELIF ELSE") 337 "readonly struct union DEF IF ELIF ELSE")
338 }); 338 });
339 339
340 }); 340 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698