MCPcopy Index your code
hub / github.com/SLiCAP/SLiCAP_python / t_PARDEF

Function t_PARDEF

SLiCAP/SLiCAPlex.py:22–70  ·  view source on GitHub ↗

r"""[a-zA-Z]\w*\s*\=\s*({[\w\(\)\/*+-\^ .]*} |([+-]?\d+\.?\d*[eE][+-]?\d+) |([+-]?\d+\.?\d*[yzafpnumkMGTP]) |([+-]?\d+\.\d*) |([+-]?\d+))

(t)

Source from the content-addressed store, hash-verified

20 #'E':'18','Z':'21','Y':'24'}
21
22def t_PARDEF(t):
23 r"""[a-zA-Z]\w*\s*\=\s*({[\w\(\)\/*+-\^ .]*}
24 |([+-]?\d+\.?\d*[eE][+-]?\d+)
25 |([+-]?\d+\.?\d*[yzafpnumkMGTP])
26 |([+-]?\d+\.\d*)
27 |([+-]?\d+))"""
28 # remove whitespace characters
29 t.value = "".join(t.value.split())
30 # split name and value/expression
31 t.value = t.value.split('=')
32 # replace scale factors in t.value[1]
33 if t.value[1][0] == '{' and t.value[1][-1] == '}':
34 # Do this for an expression
35 try:
36 sym_in = sp.sympify(t.value[1][1:-1]).atoms(sp.Symbol)
37 except:
38 sym_in = []
39 pos = 1
40 out = ''
41 for m in re.finditer(r'\d+\.?\d*[yzafpnumkMGTP]', t.value[1]):
42 out += t.value[1][pos: m.end()-1] + 'e' + _SCALEFACTORS[m.group(0)[-1]]
43 pos = m.end()
44 out += t.value[1][pos:-1]
45 sym_out = sp.sympify(out).atoms(sp.Symbol)
46 for item in sym_in:
47 if item not in sym_out:
48 _printError("Error in parameter name %s"%(str(item)), t)
49 t.value[1] = out
50 else:
51 # Do this for a numeric value: last character is scale factor
52 try:
53 scaleFactor = _SCALEFACTORS[t.value[1][-1]]
54 t.value[1] = t.value[1][0:-1] + 'e' + scaleFactor
55 except KeyError:
56 pass
57 try:
58 value = sp.sympify(t.value[1], rational=True)
59 t.value[1] = value
60 except TypeError:
61 exc_type, value, exc_traceback = sys.exc_info()
62 print('\n', value)
63 _printError("Error in expression.", t)
64 lexer.errCount += 1
65 except sp.SympifyError:
66 exc_type, value, exc_traceback = sys.exc_info()
67 print('\n', value)
68 _printError("Error in expression.", t)
69 lexer.errCount += 1
70 return t
71
72def t_CMD(t):
73 r'\.[a-zA-Z]+'

Callers

nothing calls this directly

Calls 2

_printErrorFunction · 0.85
groupMethod · 0.80

Tested by

no test coverage detected