MCPcopy Create free account
hub / github.com/numpy/numpy / parse_string

Function parse_string

numpy/distutils/conv_template.py:211–252  ·  view source on GitHub ↗
(astr, env, level, line)

Source from the content-addressed store, hash-verified

209
210replace_re = re.compile(r"@(\w+)@")
211def parse_string(astr, env, level, line) :
212 lineno = "#line %d\n" % line
213
214 # local function for string replacement, uses env
215 def replace(match):
216 name = match.group(1)
217 try :
218 val = env[name]
219 except KeyError:
220 msg = 'line %d: no definition of key "%s"'%(line, name)
221 raise ValueError(msg) from None
222 return val
223
224 code = [lineno]
225 struct = parse_structure(astr, level)
226 if struct :
227 # recurse over inner loops
228 oldend = 0
229 newlevel = level + 1
230 for sub in struct:
231 pref = astr[oldend:sub[0]]
232 head = astr[sub[0]:sub[1]]
233 text = astr[sub[1]:sub[2]]
234 oldend = sub[3]
235 newline = line + sub[4]
236 code.append(replace_re.sub(replace, pref))
237 try :
238 envlist = parse_loop_header(head)
239 except ValueError as e:
240 msg = "line %d: %s" % (newline, e)
241 raise ValueError(msg)
242 for newenv in envlist :
243 newenv.update(env)
244 newcode = parse_string(text, newenv, newlevel, newline)
245 code.extend(newcode)
246 suff = astr[oldend:]
247 code.append(replace_re.sub(replace, suff))
248 else :
249 # replace keys
250 code.append(replace_re.sub(replace, astr))
251 code.append('\n')
252 return ''.join(code)
253
254def process_str(astr):
255 code = [header]

Callers 1

process_strFunction · 0.85

Calls 4

parse_loop_headerFunction · 0.85
updateMethod · 0.80
parse_structureFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected