summaryrefslogtreecommitdiff
path: root/prolog
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-01-12 13:57:12 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-01-12 13:57:12 +0100
commit4da3793985d1d177a95d67e78dd2f4f5f52e2eab (patch)
treeede0d7204daa01f4b47d28e205fa838bf273cec6 /prolog
parentf1521c9769f9b28cf658a9255dbfc16c98870da9 (diff)
Replace prolog.util.rename_vars with rename_vars_list everywhere
Diffstat (limited to 'prolog')
-rw-r--r--prolog/util.py39
1 files changed, 5 insertions, 34 deletions
diff --git a/prolog/util.py b/prolog/util.py
index e69d4d5..c0f1ef5 100644
--- a/prolog/util.py
+++ b/prolog/util.py
@@ -79,31 +79,6 @@ def stringify(obj):
return ''.join([stringify(child) for child in obj])
# Rename variables in [tokens] to A0, A1, A2,… in order of appearance.
-def rename_vars(tokens, names=None):
- if names is None:
- names = {}
- next_id = len(names)
-
- # Return a new list.
- tokens = list(tokens)
- for i, t in enumerate(tokens):
- if t.type == 'PERIOD':
- pass
-# names.clear()
-# next_id = 0
- elif t.type == 'VARIABLE':
- if t.val.startswith('_'):
- tokens[i] = t.clone(val='A{}'.format(next_id))
- next_id += 1
- else:
- cur_name = t.val
- if cur_name not in names:
- names[cur_name] = 'A{}'.format(next_id)
- next_id += 1
- tokens[i] = t.clone(val=names[cur_name])
- return tokens
-
-# Rename variables in [tokens] to A0, A1, A2,… in order of appearance.
def rename_vars_list(tokens, names=None):
if names is None:
names = {}
@@ -112,16 +87,12 @@ def rename_vars_list(tokens, names=None):
# Return a new list.
tokens = list(tokens)
for i, t in enumerate(tokens):
- if t.type == 'VARIABLE':
- if t.val.startswith('_'):
- tokens[i] = t.clone(val='A{}'.format(next_id))
+ if t.type == 'VARIABLE' and t.val != '_':
+ cur_name = t.val
+ if cur_name not in names:
+ names[cur_name] = 'A{}'.format(next_id)
next_id += 1
- else:
- cur_name = t.val
- if cur_name not in names:
- names[cur_name] = 'A{}'.format(next_id)
- next_id += 1
- tokens[i] = t.clone(val=names[cur_name])
+ tokens[i] = t.clone(val=names[cur_name])
return tokens
# Rename variables in AST rooted at [root] to A0, A1, A2,… in order of