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