MCPcopy Index your code
hub / github.com/nodejs/node / FindEndOfExpressionInLine

Function FindEndOfExpressionInLine

tools/cpplint.py:2240–2315  ·  view source on GitHub ↗

Find the position just after the end of current parenthesized expression. Args: line: a CleansedLines line. startpos: start searching at this position. stack: nesting stack at startpos. Returns: On finding matching end: (index just after matching end, None) On

(line, startpos, stack)

Source from the content-addressed store, hash-verified

2238
2239
2240def FindEndOfExpressionInLine(line, startpos, stack):
2241 """Find the position just after the end of current parenthesized expression.
2242
2243 Args:
2244 line: a CleansedLines line.
2245 startpos: start searching at this position.
2246 stack: nesting stack at startpos.
2247
2248 Returns:
2249 On finding matching end: (index just after matching end, None)
2250 On finding an unclosed expression: (-1, None)
2251 Otherwise: (-1, new stack at end of this line)
2252 """
2253 for i in range(startpos, len(line)):
2254 char = line[i]
2255 if char in "([{":
2256 # Found start of parenthesized expression, push to expression stack
2257 stack.append(char)
2258 elif char == "<":
2259 # Found potential start of template argument list
2260 if i > 0 and line[i - 1] == "<":
2261 # Left shift operator
2262 if stack and stack[-1] == "<":
2263 stack.pop()
2264 if not stack:
2265 return (-1, None)
2266 elif i > 0 and re.search(r"\boperator\s*$", line[0:i]):
2267 # operator<, don't add to stack
2268 continue
2269 else:
2270 # Tentative start of template argument list
2271 stack.append("<")
2272 elif char in ")]}":
2273 # Found end of parenthesized expression.
2274 #
2275 # If we are currently expecting a matching '>', the pending '<'
2276 # must have been an operator. Remove them from expression stack.
2277 while stack and stack[-1] == "<":
2278 stack.pop()
2279 if not stack:
2280 return (-1, None)
2281 if (
2282 (stack[-1] == "(" and char == ")")
2283 or (stack[-1] == "[" and char == "]")
2284 or (stack[-1] == "{" and char == "}")
2285 ):
2286 stack.pop()
2287 if not stack:
2288 return (i + 1, None)
2289 else:
2290 # Mismatched parentheses
2291 return (-1, None)
2292 elif char == ">":
2293 # Found potential end of template argument list.
2294
2295 # Ignore "->" and operator functions
2296 if i > 0 and (line[i - 1] == "-" or re.search(r"\boperator\s*$", line[0 : i - 1])):
2297 continue

Callers 2

CloseExpressionFunction · 0.85
CheckCheckFunction · 0.85

Calls 4

popMethod · 0.80
rangeFunction · 0.50
appendMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…