Parses the line and returns a 3-tuple: (mode, code, insertion). `mode` is the next mode (or state) of the lexer, and is always equal to 'input', 'output', or 'tb'. `code` is a portion of the line that should be added to the buffer corresponding to the next
(self, line)
| 358 | self.insertions = [] |
| 359 | |
| 360 | def get_mci(self, line): |
| 361 | """ |
| 362 | Parses the line and returns a 3-tuple: (mode, code, insertion). |
| 363 | |
| 364 | `mode` is the next mode (or state) of the lexer, and is always equal |
| 365 | to 'input', 'output', or 'tb'. |
| 366 | |
| 367 | `code` is a portion of the line that should be added to the buffer |
| 368 | corresponding to the next mode and eventually lexed by another lexer. |
| 369 | For example, `code` could be Python code if `mode` were 'input'. |
| 370 | |
| 371 | `insertion` is a 3-tuple (index, token, text) representing an |
| 372 | unprocessed "token" that will be inserted into the stream of tokens |
| 373 | that are created from the buffer once we change modes. This is usually |
| 374 | the input or output prompt. |
| 375 | |
| 376 | In general, the next mode depends on current mode and on the contents |
| 377 | of `line`. |
| 378 | |
| 379 | """ |
| 380 | # To reduce the number of regex match checks, we have multiple |
| 381 | # 'if' blocks instead of 'if-elif' blocks. |
| 382 | |
| 383 | # Check for possible end of input |
| 384 | in2_match = self.in2_regex.match(line) |
| 385 | in2_match_rstrip = self.in2_regex_rstrip.match(line) |
| 386 | if (in2_match and in2_match.group().rstrip() == line.rstrip()) or \ |
| 387 | in2_match_rstrip: |
| 388 | end_input = True |
| 389 | else: |
| 390 | end_input = False |
| 391 | if end_input and self.mode != 'tb': |
| 392 | # Only look for an end of input when not in tb mode. |
| 393 | # An ellipsis could appear within the traceback. |
| 394 | mode = 'output' |
| 395 | code = u'' |
| 396 | insertion = (0, Generic.Prompt, line) |
| 397 | return mode, code, insertion |
| 398 | |
| 399 | # Check for output prompt |
| 400 | out_match = self.out_regex.match(line) |
| 401 | out_match_rstrip = self.out_regex_rstrip.match(line) |
| 402 | if out_match or out_match_rstrip: |
| 403 | mode = 'output' |
| 404 | if out_match: |
| 405 | idx = out_match.end() |
| 406 | else: |
| 407 | idx = out_match_rstrip.end() |
| 408 | code = line[idx:] |
| 409 | # Use the 'heading' token for output. We cannot use Generic.Error |
| 410 | # since it would conflict with exceptions. |
| 411 | insertion = (0, Generic.Heading, line[:idx]) |
| 412 | return mode, code, insertion |
| 413 | |
| 414 | |
| 415 | # Check for input or continuation prompt (non stripped version) |
| 416 | in1_match = self.in1_regex.match(line) |
| 417 | if in1_match or (in2_match and self.mode != 'tb'): |
no test coverage detected