def _argsplit_fortran(argtxt):
txt = _INLINE_EVAL_REGION_REGEXP.sub(_blank_match, argtxt)
splitpos = [-1]
quote = None
closing_brace_stack = []
closing_brace = None
for ind, char in enumerate(txt):
if quote:
if char == quote:
quote = None
continue
if char in _QUOTES_FORTRAN:
quote = char
continue
if char in _OPENING_BRACKETS_FORTRAN:
closing_brace_stack.append(closing_brace)
ind = _OPENING_BRACKETS_FORTRAN.index(char)
closing_brace = _CLOSING_BRACKETS_FORTRAN[ind]
continue
if char in _CLOSING_BRACKETS_FORTRAN:
if char == closing_brace:
closing_brace = closing_brace_stack.pop(-1)
continue
else:
msg = "unexpected closing delimiter '{0}' in expression '{1}' "\
"at position {2}".format(char, argtxt, ind + 1)
raise FyppFatalError(msg)
if not closing_brace and char == _ARGUMENT_SPLIT_CHAR_FORTRAN:
splitpos.append(ind)
if quote or closing_brace:
msg = "open quotes or brackets in expression '{0}'".format(argtxt)
raise FyppFatalError(msg)
splitpos.append(len(txt))
fragments = [argtxt[start + 1 : end]
for start, end in zip(splitpos, splitpos[1:])]
return fragments
评论列表
文章目录