MCPcopy
hub / github.com/numpy/numpy / parse_structure

Function parse_structure

numpy/_build_utils/conv_template.py:103–132  ·  view source on GitHub ↗

The returned line number is from the beginning of the string, starting at zero. Returns an empty list if no loops found.

(astr, level)

Source from the content-addressed store, hash-verified

101"""
102# Parse string for repeat loops
103def parse_structure(astr, level):
104 """
105 The returned line number is from the beginning of the string, starting
106 at zero. Returns an empty list if no loops found.
107
108 """
109 if level == 0:
110 loopbeg = "/**begin repeat"
111 loopend = "/**end repeat**/"
112 else:
113 loopbeg = f"/**begin repeat{level}"
114 loopend = f"/**end repeat{level}**/"
115
116 ind = 0
117 line = 0
118 spanlist = []
119 while True:
120 start = astr.find(loopbeg, ind)
121 if start == -1:
122 break
123 start2 = astr.find("*/", start)
124 start2 = astr.find("\n", start2)
125 fini1 = astr.find(loopend, start2)
126 fini2 = astr.find("\n", fini1)
127 line += astr.count("\n", ind, start2 + 1)
128 spanlist.append((start, start2 + 1, fini1, fini2 + 1, line))
129 line += astr.count("\n", start2 + 1, fini2)
130 ind = fini2
131 spanlist.sort()
132 return spanlist
133
134
135def paren_repl(obj):

Callers 1

parse_stringFunction · 0.70

Calls 3

findMethod · 0.80
countMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…