MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / FindEndOfExpressionInLine

Function FindEndOfExpressionInLine

src/tests/coding/cpplint.py:1996–2071  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 2

CloseExpressionFunction · 0.85
CheckCheckFunction · 0.85

Calls 2

SearchFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected