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

Function FindStartOfExpressionInLine

src/tests/coding/cpplint.py:2118–2192  ·  view source on GitHub ↗

Find position at the matching start of current expression. This is almost the reverse of FindEndOfExpressionInLine, but note that the input position and returned position differs by 1. Args: line: a CleansedLines line. endpos: start searching at this position. stack: nesting stac

(line, endpos, stack)

Source from the content-addressed store, hash-verified

2116
2117
2118def FindStartOfExpressionInLine(line, endpos, stack):
2119 """Find position at the matching start of current expression.
2120
2121 This is almost the reverse of FindEndOfExpressionInLine, but note
2122 that the input position and returned position differs by 1.
2123
2124 Args:
2125 line: a CleansedLines line.
2126 endpos: start searching at this position.
2127 stack: nesting stack at endpos.
2128
2129 Returns:
2130 On finding matching start: (index at matching start, None)
2131 On finding an unclosed expression: (-1, None)
2132 Otherwise: (-1, new stack at beginning of this line)
2133 """
2134 i = endpos
2135 while i >= 0:
2136 char = line[i]
2137 if char in ')]}':
2138 # Found end of expression, push to expression stack
2139 stack.append(char)
2140 elif char == '>':
2141 # Found potential end of template argument list.
2142 #
2143 # Ignore it if it's a "->" or ">=" or "operator>"
2144 if (i > 0 and
2145 (line[i - 1] == '-' or
2146 Match(r'\s>=\s', line[i - 1:]) or
2147 Search(r'\boperator\s*$', line[0:i]))):
2148 i -= 1
2149 else:
2150 stack.append('>')
2151 elif char == '<':
2152 # Found potential start of template argument list
2153 if i > 0 and line[i - 1] == '<':
2154 # Left shift operator
2155 i -= 1
2156 else:
2157 # If there is a matching '>', we can pop the expression stack.
2158 # Otherwise, ignore this '<' since it must be an operator.
2159 if stack and stack[-1] == '>':
2160 stack.pop()
2161 if not stack:
2162 return (i, None)
2163 elif char in '([{':
2164 # Found start of expression.
2165 #
2166 # If there are any unmatched '>' on the stack, they must be
2167 # operators. Remove those.
2168 while stack and stack[-1] == '>':
2169 stack.pop()
2170 if not stack:
2171 return (-1, None)
2172 if ((char == '(' and stack[-1] == ')') or
2173 (char == '[' and stack[-1] == ']') or
2174 (char == '{' and stack[-1] == '}')):
2175 stack.pop()

Callers 1

ReverseCloseExpressionFunction · 0.85

Calls 3

SearchFunction · 0.85
MatchFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected