MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / tokenLexer

Function tokenLexer

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

Source from the content-addressed store, hash-verified

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

Callers 1

python.jsFile · 0.70

Calls 3

indentFunction · 0.70
dedentFunction · 0.70
matchMethod · 0.45

Tested by

no test coverage detected