`tamsin parse` and `tamsin-ast.tamsin` output reprified terms.
Cat's Eye Technologies
10 years ago
4 | 4 |
-------
|
5 | 5 |
|
6 | 6 |
### language ###
|
|
7 |
|
|
8 |
* (Partially) defined what it means to `reprify` a term.
|
|
9 |
* Clarified some matters as implementation-defined.
|
7 | 10 |
|
8 | 11 |
### modules ###
|
9 | 12 |
|
|
15 | 18 |
|
16 | 19 |
* Virtually full support for user-defined modules. (Not external ones
|
17 | 20 |
yet though.)
|
|
21 |
* `tamsin parse` and `tamsin-parser.tamsin` output reprified terms.
|
18 | 22 |
|
19 | 23 |
0.2
|
20 | 24 |
---
|
2 | 2 |
|
3 | 3 |
* `$:deep_reverse`
|
4 | 4 |
* use Tamsin repr in error messages
|
5 | |
* use Tamsin repr in `tamsin parse` and in `tamsin-parser.tamsin`
|
|
5 |
* definition of reprification needs work (e.g. `"` should repr to `'"'`)
|
|
6 |
* python impl should take >1 source file on cmdline (external modules)
|
6 | 7 |
|
7 | 8 |
### more tests ###
|
8 | 9 |
|
3 | 3 |
# Note that this may contain support for some features which are not in
|
4 | 4 |
# the current released or pre-released version.
|
5 | 5 |
|
6 | |
main = grammar using scanner.
|
|
6 |
main = (grammar using scanner) → P & $:repr(P).
|
7 | 7 |
|
8 | 8 |
grammar = {"@" & pragma & "."} &
|
9 | 9 |
LM ← nil &
|
3 | 3 |
# Distributed under a BSD-style license; see LICENSE for more information.
|
4 | 4 |
|
5 | 5 |
# Note that __str__ and __repr__ perform very different tasks:
|
6 | |
# __str__ : make a string that looks like a Tamsin term
|
|
6 |
# __str__ : make a string that looks like a Tamsin term (reprify)
|
7 | 7 |
# __repr__ : make a string that is valid Python code for constructing the AST
|
8 | 8 |
|
9 | |
from tamsin.term import Variable
|
|
9 |
from tamsin.term import Term, Variable
|
10 | 10 |
|
11 | 11 |
|
12 | 12 |
def format_list(l):
|
13 | 13 |
if len(l) == 0:
|
14 | 14 |
return 'nil'
|
15 | 15 |
else:
|
16 | |
return 'list(%s, %s)' % (l[0], format_list(l[1:]))
|
|
16 |
s = l[0]
|
|
17 |
if isinstance(l[0], Term):
|
|
18 |
s = l[0].repr()
|
|
19 |
return 'list(%s, %s)' % (s, format_list(l[1:]))
|
17 | 20 |
|
18 | 21 |
|
19 | 22 |
class AST(object):
|
|
136 | 139 |
self.rhs
|
137 | 140 |
)
|
138 | 141 |
|
|
142 |
|
139 | 143 |
class Or(AST):
|
140 | 144 |
def __init__(self, lhs, rhs):
|
141 | 145 |
self.lhs = lhs
|
|
252 | 256 |
)
|
253 | 257 |
|
254 | 258 |
def __str__(self):
|
255 | |
return "%s%s" % (
|
256 | |
self.lhs,
|
257 | |
self.rhs
|
258 | |
)
|
|
259 |
lhs = self.lhs
|
|
260 |
if isinstance(lhs, Term):
|
|
261 |
lhs = lhs.repr()
|
|
262 |
rhs = self.rhs
|
|
263 |
if isinstance(rhs, Term):
|
|
264 |
rhs = rhs.repr()
|
|
265 |
return "%s%s" % (lhs, rhs)
|
259 | 266 |
|
260 | 267 |
|
261 | 268 |
class Using(AST):
|
|
293 | 300 |
def __str__(self):
|
294 | 301 |
return "fold(%s, %s)" % (
|
295 | 302 |
self.rule,
|
296 | |
self.initial
|
297 | |
)
|
|
303 |
self.initial.repr()
|
|
304 |
)
|