MCPcopy Create free account
hub / github.com/nwutils/nw-sample-apps / tokenLexer

Function tokenLexer

mini-code-edit/cm/mode/python/python.js:245–301  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

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

Callers 1

python.jsFile · 0.70

Calls 2

indentFunction · 0.70
dedentFunction · 0.70

Tested by

no test coverage detected