summaryrefslogtreecommitdiff
path: root/prolog
diff options
context:
space:
mode:
Diffstat (limited to 'prolog')
-rw-r--r--prolog/util.py24
1 files changed, 7 insertions, 17 deletions
diff --git a/prolog/util.py b/prolog/util.py
index fc243f2..eb026fe 100644
--- a/prolog/util.py
+++ b/prolog/util.py
@@ -19,24 +19,14 @@ operators = set([
'PLUS', 'MINUS', 'STAR', 'DIV', 'IDIV', 'MOD',
'POW', 'SEMI'
])
-def stringify(tokens, indent=''):
- s = indent
- for t in tokens:
- if t[0] in operators:
- s += ' '
-
- if t[0] == 'FROM':
- s += ':-\n ' + indent
- elif t[0] == 'PERIOD':
- s += '.\n' + indent
- elif t[0] == 'COMMA':
- s += ', '
+def stringify(tokens):
+ def token_str(t):
+ if t[0] in ('PERIOD', 'COMMA'):
+ return t[1] + ' '
elif t[0] in operators:
- s += t[1] + ' '
- else:
- s += t[1]
-
- return s.strip().replace('\n', ' ').replace('\t', ' ')
+ return ' ' + t[1] + ' '
+ return t[1]
+ return ''.join(map(token_str, tokens))
# return a list of lines in 'code', and a list of rule indexes
def decompose(code):