MCPcopy Create free account
hub / github.com/apache/mesos / FindStartOfExpressionInLine

Function FindStartOfExpressionInLine

support/cpplint.py:1646–1720  ·  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

1644
1645
1646def FindStartOfExpressionInLine(line, endpos, stack):
1647 """Find position at the matching start of current expression.
1648
1649 This is almost the reverse of FindEndOfExpressionInLine, but note
1650 that the input position and returned position differs by 1.
1651
1652 Args:
1653 line: a CleansedLines line.
1654 endpos: start searching at this position.
1655 stack: nesting stack at endpos.
1656
1657 Returns:
1658 On finding matching start: (index at matching start, None)
1659 On finding an unclosed expression: (-1, None)
1660 Otherwise: (-1, new stack at beginning of this line)
1661 """
1662 i = endpos
1663 while i >= 0:
1664 char = line[i]
1665 if char in ')]}':
1666 # Found end of expression, push to expression stack
1667 stack.append(char)
1668 elif char == '>':
1669 # Found potential end of template argument list.
1670 #
1671 # Ignore it if it's a "->" or ">=" or "operator>"
1672 if (i > 0 and
1673 (line[i - 1] == '-' or
1674 Match(r'\s>=\s', line[i - 1:]) or
1675 Search(r'\boperator\s*$', line[0:i]))):
1676 i -= 1
1677 else:
1678 stack.append('>')
1679 elif char == '<':
1680 # Found potential start of template argument list
1681 if i > 0 and line[i - 1] == '<':
1682 # Left shift operator
1683 i -= 1
1684 else:
1685 # If there is a matching '>', we can pop the expression stack.
1686 # Otherwise, ignore this '<' since it must be an operator.
1687 if stack and stack[-1] == '>':
1688 stack.pop()
1689 if not stack:
1690 return (i, None)
1691 elif char in '([{':
1692 # Found start of expression.
1693 #
1694 # If there are any unmatched '>' on the stack, they must be
1695 # operators. Remove those.
1696 while stack and stack[-1] == '>':
1697 stack.pop()
1698 if not stack:
1699 return (-1, None)
1700 if ((char == '(' and stack[-1] == ')') or
1701 (char == '[' and stack[-1] == ']') or
1702 (char == '{' and stack[-1] == '}')):
1703 stack.pop()

Callers 1

ReverseCloseExpressionFunction · 0.85

Calls 3

MatchFunction · 0.85
SearchFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected