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)
| 2360 | |
| 2361 | |
| 2362 | def FindStartOfExpressionInLine(line, endpos, stack): |
| 2363 | """Find position at the matching start of current expression. |
| 2364 | |
| 2365 | This is almost the reverse of FindEndOfExpressionInLine, but note |
| 2366 | that the input position and returned position differs by 1. |
| 2367 | |
| 2368 | Args: |
| 2369 | line: a CleansedLines line. |
| 2370 | endpos: start searching at this position. |
| 2371 | stack: nesting stack at endpos. |
| 2372 | |
| 2373 | Returns: |
| 2374 | On finding matching start: (index at matching start, None) |
| 2375 | On finding an unclosed expression: (-1, None) |
| 2376 | Otherwise: (-1, new stack at beginning of this line) |
| 2377 | """ |
| 2378 | i = endpos |
| 2379 | while i >= 0: |
| 2380 | char = line[i] |
| 2381 | if char in ")]}": |
| 2382 | # Found end of expression, push to expression stack |
| 2383 | stack.append(char) |
| 2384 | elif char == ">": |
| 2385 | # Found potential end of template argument list. |
| 2386 | # |
| 2387 | # Ignore it if it's a "->" or ">=" or "operator>" |
| 2388 | if i > 0 and ( |
| 2389 | line[i - 1] == "-" |
| 2390 | or re.match(r"\s>=\s", line[i - 1 :]) |
| 2391 | or re.search(r"\boperator\s*$", line[0:i]) |
| 2392 | ): |
| 2393 | i -= 1 |
| 2394 | else: |
| 2395 | stack.append(">") |
| 2396 | elif char == "<": |
| 2397 | # Found potential start of template argument list |
| 2398 | if i > 0 and line[i - 1] == "<": |
| 2399 | # Left shift operator |
| 2400 | i -= 1 |
| 2401 | else: |
| 2402 | # If there is a matching '>', we can pop the expression stack. |
| 2403 | # Otherwise, ignore this '<' since it must be an operator. |
| 2404 | if stack and stack[-1] == ">": |
| 2405 | stack.pop() |
| 2406 | if not stack: |
| 2407 | return (i, None) |
| 2408 | elif char in "([{": |
| 2409 | # Found start of expression. |
| 2410 | # |
| 2411 | # If there are any unmatched '>' on the stack, they must be |
| 2412 | # operators. Remove those. |
| 2413 | while stack and stack[-1] == ">": |
| 2414 | stack.pop() |
| 2415 | if not stack: |
| 2416 | return (-1, None) |
| 2417 | if ( |
| 2418 | (char == "(" and stack[-1] == ")") |
| 2419 | or (char == "[" and stack[-1] == "]") |
no test coverage detected
searching dependent graphs…