MCPcopy
hub / github.com/pandao/editor.md / tokenLexer

Function tokenLexer

lib/codemirror/mode/python/python.js:247–298  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

245 }
246
247 function tokenLexer(stream, state) {
248 var style = state.tokenize(stream, state);
249 var current = stream.current();
250
251 // Handle '.' connected identifiers
252 if (current == ".") {
253 style = stream.match(identifiers, false) ? null : ERRORCLASS;
254 if (style == null && state.lastStyle == "meta") {
255 // Apply 'meta' style to '.' connected identifiers when
256 // appropriate.
257 style = "meta";
258 }
259 return style;
260 }
261
262 // Handle decorators
263 if (current == "@"){
264 if(parserConf.version && parseInt(parserConf.version, 10) == 3){
265 return stream.match(identifiers, false) ? "meta" : "operator";
266 } else {
267 return stream.match(identifiers, false) ? "meta" : ERRORCLASS;
268 }
269 }
270
271 if ((style == "variable" || style == "builtin")
272 && state.lastStyle == "meta")
273 style = "meta";
274
275 // Handle scope changes.
276 if (current == "pass" || current == "return")
277 state.dedent += 1;
278
279 if (current == "lambda") state.lambda = true;
280 if (current == ":" && !state.lambda && top(state).type == "py")
281 pushScope(stream, state, "py");
282
283 var delimiter_index = current.length == 1 ? "[({".indexOf(current) : -1;
284 if (delimiter_index != -1)
285 pushScope(stream, state, "])}".slice(delimiter_index, delimiter_index+1));
286
287 delimiter_index = "])}".indexOf(current);
288 if (delimiter_index != -1) {
289 if (top(state).type == current) state.scopes.pop();
290 else return ERRORCLASS;
291 }
292 if (state.dedent > 0 && stream.eol() && top(state).type == "py") {
293 if (state.scopes.length > 1) state.scopes.pop();
294 state.dedent -= 1;
295 }
296
297 return style;
298 }
299
300 var external = {
301 startState: function(basecolumn) {

Callers 1

python.jsFile · 0.70

Calls 2

topFunction · 0.85
pushScopeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…