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