summaryrefslogtreecommitdiff
path: root/prolog/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/util.py')
-rw-r--r--prolog/util.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/prolog/util.py b/prolog/util.py
index b7e536b..0ab3c8b 100644
--- a/prolog/util.py
+++ b/prolog/util.py
@@ -27,6 +27,15 @@ def stringify(tokens):
return str(t)
return ''.join(map(token_str, tokens))
+# Yield the sequence of rules in [code].
+def split(code):
+ tokens = tokenize(code)
+ start = 0
+ for idx, token in enumerate(tokens):
+ if token.type == 'PERIOD' and idx - start > 1:
+ yield stringify(tokens[start:idx])
+ start = idx + 1
+
# return a list of lines in 'code', and a list of rule indexes
def decompose(code):
lines = []