diff options
author | Pearu Peterson <pearu.peterson@gmail.com> | 2006-06-30 13:36:13 +0000 |
---|---|---|
committer | Pearu Peterson <pearu.peterson@gmail.com> | 2006-06-30 13:36:13 +0000 |
commit | ec1662fb0182a87ebf39ec476109becfc7a8cdb1 (patch) | |
tree | 8fccdddd721e148af03e0f7849920bcd6fc560f9 /numpy/f2py/lib/splitline.py | |
parent | 906855403e7b9853222af1c715202c86b226b71e (diff) | |
download | numpy-ec1662fb0182a87ebf39ec476109becfc7a8cdb1.tar.gz |
Writting parser unittests, fixed bugs.
Diffstat (limited to 'numpy/f2py/lib/splitline.py')
-rw-r--r-- | numpy/f2py/lib/splitline.py | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/numpy/f2py/lib/splitline.py b/numpy/f2py/lib/splitline.py index b95e0d014..a1148a502 100644 --- a/numpy/f2py/lib/splitline.py +++ b/numpy/f2py/lib/splitline.py @@ -28,7 +28,9 @@ def split2(line, lower=False): """ return LineSplitter(line,lower=lower).split2() -_f2py_str_findall = re.compile(r"'_F2PY_STRING_CONSTANT_\d+_'").findall +_f2py_str_findall = re.compile(r"_F2PY_STRING_CONSTANT_\d+_").findall +_is_name = re.compile(r'\w*\Z',re.I).match +_is_simple_str = re.compile(r'\w*\Z',re.I).match def string_replace_map(line, lower=False, _cache={'index':0,'pindex':0}): @@ -41,31 +43,33 @@ def string_replace_map(line, lower=False, string_map = {} rev_string_map = {} for item in splitquote(line, lower=lower)[0]: - if isinstance(item, String): + if isinstance(item, String) and not _is_simple_str(item[1:-1]): key = rev_string_map.get(item) if key is None: _cache['index'] += 1 index = _cache['index'] - key = "'_F2PY_STRING_CONSTANT_%s_'" % (index) - string_map[key] = item - rev_string_map[item] = key - items.append(key) + key = "_F2PY_STRING_CONSTANT_%s_" % (index) + it = item[1:-1] + string_map[key] = it + rev_string_map[it] = key + items.append(item[0]+key+item[-1]) else: items.append(item) newline = ''.join(items) items = [] expr_keys = [] for item in splitparen(newline): - if isinstance(item, ParenString): + if isinstance(item, ParenString) and not _is_name(item[1:-1]): key = rev_string_map.get(item) if key is None: _cache['pindex'] += 1 index = _cache['pindex'] - key = '(F2PY_EXPR_TUPLE_%s)' % (index) - string_map[key] = item - rev_string_map[item] = key + key = 'F2PY_EXPR_TUPLE_%s' % (index) + it = item[1:-1] + string_map[key] = it + rev_string_map[it] = key expr_keys.append(key) - items.append(key) + items.append(item[0]+key+item[-1]) else: items.append(item) found_keys = set() |