MCPcopy Create free account
hub / github.com/alibaba/GraphScope / FindStartOfExpressionInLine

Function FindStartOfExpressionInLine

analytical_engine/misc/cpplint.py:2122–2196  ·  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

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

Callers 1

ReverseCloseExpressionFunction · 0.85

Calls 4

SearchFunction · 0.85
MatchFunction · 0.70
appendMethod · 0.65
popMethod · 0.45

Tested by

no test coverage detected