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)
| 2009 | |
| 2010 | |
| 2011 | def FindEndOfExpressionInLine(line, startpos, stack): |
| 2012 | """Find the position just after the end of current parenthesized expression. |
| 2013 | |
| 2014 | Args: |
| 2015 | line: a CleansedLines line. |
| 2016 | startpos: start searching at this position. |
| 2017 | stack: nesting stack at startpos. |
| 2018 | |
| 2019 | Returns: |
| 2020 | On finding matching end: (index just after matching end, None) |
| 2021 | On finding an unclosed expression: (-1, None) |
| 2022 | Otherwise: (-1, new stack at end of this line) |
| 2023 | """ |
| 2024 | for i in xrange(startpos, len(line)): |
| 2025 | char = line[i] |
| 2026 | if char in '([{': |
| 2027 | # Found start of parenthesized expression, push to expression stack |
| 2028 | stack.append(char) |
| 2029 | elif char == '<': |
| 2030 | # Found potential start of template argument list |
| 2031 | if i > 0 and line[i - 1] == '<': |
| 2032 | # Left shift operator |
| 2033 | if stack and stack[-1] == '<': |
| 2034 | stack.pop() |
| 2035 | if not stack: |
| 2036 | return (-1, None) |
| 2037 | elif i > 0 and Search(r'\boperator\s*$', line[0:i]): |
| 2038 | # operator<, don't add to stack |
| 2039 | continue |
| 2040 | else: |
| 2041 | # Tentative start of template argument list |
| 2042 | stack.append('<') |
| 2043 | elif char in ')]}': |
| 2044 | # Found end of parenthesized expression. |
| 2045 | # |
| 2046 | # If we are currently expecting a matching '>', the pending '<' |
| 2047 | # must have been an operator. Remove them from expression stack. |
| 2048 | while stack and stack[-1] == '<': |
| 2049 | stack.pop() |
| 2050 | if not stack: |
| 2051 | return (-1, None) |
| 2052 | if ((stack[-1] == '(' and char == ')') or |
| 2053 | (stack[-1] == '[' and char == ']') or |
| 2054 | (stack[-1] == '{' and char == '}')): |
| 2055 | stack.pop() |
| 2056 | if not stack: |
| 2057 | return (i + 1, None) |
| 2058 | else: |
| 2059 | # Mismatched parentheses |
| 2060 | return (-1, None) |
| 2061 | elif char == '>': |
| 2062 | # Found potential end of template argument list. |
| 2063 | |
| 2064 | # Ignore "->" and operator functions |
| 2065 | if (i > 0 and |
| 2066 | (line[i - 1] == '-' or Search(r'\boperator\s*$', line[0:i - 1]))): |
| 2067 | continue |
| 2068 |
no test coverage detected