diff options
author | Timotej Lazar <timotej.lazar@araneo.org> | 2014-12-08 20:43:22 +0100 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-08-11 14:26:00 +0200 |
commit | f4bee33bfae518ac04e67232d301900bcf3ebd4e (patch) | |
tree | abb46e2c365d2a81ad1e081f104be86399664dae /prolog/util.py | |
parent | 8d468ca2abf07eac9092b08390856f761dd701cd (diff) |
Start refactoring testing code
Testing logic now lives in PrologEngine. The engine now has some notion
of problems and users, which is necessary to avoid repeatedly loading
code into Prolog.
TODO:
- support library loading
- fix PrologEngine.test for unusual cases (more than one solution, …)
- memoization of correct answers
Diffstat (limited to 'prolog/util.py')
-rw-r--r-- | prolog/util.py | 9 |
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 = [] |