MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / tokenLexer

Function tokenLexer

lib/web/CodeMirror/mode/python/python.js:300–341  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

298 }
299
300 function tokenLexer(stream, state) {
301 if (stream.sol()) state.beginningOfLine = true;
302
303 var style = state.tokenize(stream, state);
304 var current = stream.current();
305
306 // Handle decorators
307 if (state.beginningOfLine && current == "@")
308 return stream.match(identifiers, false) ? "meta" : py3 ? "operator" : ERRORCLASS;
309
310 if (/\S/.test(current)) state.beginningOfLine = false;
311
312 if ((style == "variable" || style == "builtin")
313 && state.lastToken == "meta")
314 style = "meta";
315
316 // Handle scope changes.
317 if (current == "pass" || current == "return")
318 state.dedent += 1;
319
320 if (current == "lambda") state.lambda = true;
321 if (current == ":" && !state.lambda && top(state).type == "py")
322 pushPyScope(state);
323
324 if (current.length == 1 && !/string|comment/.test(style)) {
325 var delimiter_index = "[({".indexOf(current);
326 if (delimiter_index != -1)
327 pushBracketScope(stream, state, "])}".slice(delimiter_index, delimiter_index+1));
328
329 delimiter_index = "])}".indexOf(current);
330 if (delimiter_index != -1) {
331 if (top(state).type == current) state.indent = state.scopes.pop().offset - hangingIndent
332 else return ERRORCLASS;
333 }
334 }
335 if (state.dedent > 0 && stream.eol() && top(state).type == "py") {
336 if (state.scopes.length > 1) state.scopes.pop();
337 state.dedent -= 1;
338 }
339
340 return style;
341 }
342
343 var external = {
344 startState: function(basecolumn) {

Callers 1

python.jsFile · 0.70

Calls 10

topFunction · 0.85
pushPyScopeFunction · 0.85
pushBracketScopeFunction · 0.85
solMethod · 0.80
currentMethod · 0.80
indexOfMethod · 0.80
eolMethod · 0.80
matchMethod · 0.45
testMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected