summaryrefslogtreecommitdiff
path: root/prolog/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/util.py')
-rw-r--r--prolog/util.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/prolog/util.py b/prolog/util.py
index e5a93e2..48e3345 100644
--- a/prolog/util.py
+++ b/prolog/util.py
@@ -156,6 +156,17 @@ def rename_vars(tokens, names=None):
tokens[i] = Token('VARIABLE', names[cur_name])
return tokens
+# Helper function to remove trailing punctuation from lines and rename
+# variables to A1,A2,A3,… (potentially using [var_names]). Return a tuple.
+def normalized(line, var_names=None):
+ # Remove trailing punctuation.
+ i = len(line)
+ while i > 0:
+ if line[i-1].type not in ('COMMA', 'PERIOD', 'SEMI'):
+ break
+ i -= 1
+ return tuple(rename_vars(line[:i], var_names))
+
# transformation = before → after; applied on line which is part of rule
# return mapping from formal vars in before+after to actual vars in rule
# line and rule should of course not be normalized