MCPcopy Index your code
hub / github.com/cpplint/cpplint / FindStartOfExpressionInLine

Function FindStartOfExpressionInLine

cpplint.py:2317–2394  ·  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:

(line, endpos, stack)

Source from the content-addressed store, hash-verified

2315
2316
2317def FindStartOfExpressionInLine(line, endpos, stack):
2318 """Find position at the matching start of current expression.
2319
2320 This is almost the reverse of FindEndOfExpressionInLine, but note
2321 that the input position and returned position differs by 1.
2322
2323 Args:
2324 line: a CleansedLines line.
2325 endpos: start searching at this position.
2326 stack: nesting stack at endpos.
2327
2328 Returns:
2329 On finding matching start: (index at matching start, None)
2330 On finding an unclosed expression: (-1, None)
2331 Otherwise: (-1, new stack at beginning of this line)
2332 """
2333 i = endpos
2334 while i >= 0:
2335 char = line[i]
2336 if char in ")]}":
2337 # Found end of expression, push to expression stack
2338 stack.append(char)
2339 elif char == ">":
2340 # Found potential end of template argument list.
2341 #
2342 # Ignore it if it's a "->" or ">=" or "operator>"
2343 if i > 0 and (
2344 line[i - 1] == "-"
2345 or re.match(r"\s>=\s", line[i - 1 :])
2346 or re.search(r"\boperator\s*$", line[0:i])
2347 ):
2348 i -= 1
2349 else:
2350 stack.append(">")
2351 elif char == "<":
2352 # Found potential start of template argument list
2353 if i > 0 and line[i - 1] == "<":
2354 # Left shift operator
2355 i -= 1
2356 else:
2357 # If there is a matching '>', we can pop the expression stack.
2358 # Otherwise, ignore this '<' since it must be an operator.
2359 if stack and stack[-1] == ">":
2360 stack.pop()
2361 if not stack:
2362 return (i, None)
2363 elif char in "([{":
2364 # Found start of expression.
2365 #
2366 # If there are any unmatched '>' on the stack, they must be
2367 # operators. Remove those.
2368 while stack and stack[-1] == ">":
2369 stack.pop()
2370 if not stack:
2371 return (-1, None)
2372 if (
2373 (char == "(" and stack[-1] == ")")
2374 or (char == "[" and stack[-1] == "]")

Callers 1

ReverseCloseExpressionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected