MCPcopy Index your code
hub / github.com/csev/py4e / tokenLexer

Function tokenLexer

tools/pythonauto/static/codemirrorepl/python.js:253–309  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

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

Callers 1

python.jsFile · 0.70

Calls 4

sliceMethod · 0.80
indentFunction · 0.70
dedentFunction · 0.70
shiftMethod · 0.45

Tested by

no test coverage detected