Find the position just after the end of current parenthesized expression. Args: line: a CleansedLines line. startpos: start searching at this position. stack: nesting stack at startpos. Returns: On finding matching end: (index just after matching end, None) On finding an un
(line, startpos, stack)
| 1491 | |
| 1492 | |
| 1493 | def FindEndOfExpressionInLine(line, startpos, stack): |
| 1494 | """Find the position just after the end of current parenthesized expression. |
| 1495 | |
| 1496 | Args: |
| 1497 | line: a CleansedLines line. |
| 1498 | startpos: start searching at this position. |
| 1499 | stack: nesting stack at startpos. |
| 1500 | |
| 1501 | Returns: |
| 1502 | On finding matching end: (index just after matching end, None) |
| 1503 | On finding an unclosed expression: (-1, None) |
| 1504 | Otherwise: (-1, new stack at end of this line) |
| 1505 | """ |
| 1506 | for i in range(startpos, len(line)): |
| 1507 | char = line[i] |
| 1508 | if char in '([{': |
| 1509 | # Found start of parenthesized expression, push to expression stack |
| 1510 | stack.append(char) |
| 1511 | elif char == '<': |
| 1512 | # Found potential start of template argument list |
| 1513 | if i > 0 and line[i - 1] == '<': |
| 1514 | # Left shift operator |
| 1515 | if stack and stack[-1] == '<': |
| 1516 | stack.pop() |
| 1517 | if not stack: |
| 1518 | return (-1, None) |
| 1519 | elif i > 0 and Search(r'\boperator\s*$', line[0:i]): |
| 1520 | # operator<, don't add to stack |
| 1521 | continue |
| 1522 | else: |
| 1523 | # Tentative start of template argument list |
| 1524 | stack.append('<') |
| 1525 | elif char in ')]}': |
| 1526 | # Found end of parenthesized expression. |
| 1527 | # |
| 1528 | # If we are currently expecting a matching '>', the pending '<' |
| 1529 | # must have been an operator. Remove them from expression stack. |
| 1530 | while stack and stack[-1] == '<': |
| 1531 | stack.pop() |
| 1532 | if not stack: |
| 1533 | return (-1, None) |
| 1534 | if ((stack[-1] == '(' and char == ')') or |
| 1535 | (stack[-1] == '[' and char == ']') or |
| 1536 | (stack[-1] == '{' and char == '}')): |
| 1537 | stack.pop() |
| 1538 | if not stack: |
| 1539 | return (i + 1, None) |
| 1540 | else: |
| 1541 | # Mismatched parentheses |
| 1542 | return (-1, None) |
| 1543 | elif char == '>': |
| 1544 | # Found potential end of template argument list. |
| 1545 | |
| 1546 | # Ignore "->" and operator functions |
| 1547 | if (i > 0 and |
| 1548 | (line[i - 1] == '-' or Search(r'\boperator\s*$', line[0:i - 1]))): |
| 1549 | continue |
| 1550 |
no test coverage detected