MCPcopy Index your code
hub / github.com/tensorflow/tfjs / FindStartOfExpressionInLine

Function FindStartOfExpressionInLine

tfjs-backend-wasm/tools/cpplint.py:1641–1715  ·  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

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

Callers 1

ReverseCloseExpressionFunction · 0.85

Calls 4

MatchFunction · 0.85
SearchFunction · 0.85
appendMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…