git @ Cat's Eye Technologies Tamsin / 4e6ae54
`tamsin parse` and `tamsin-ast.tamsin` output reprified terms. Cat's Eye Technologies 10 years ago
5 changed file(s) with 26 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
44 -------
55
66 ### language ###
7
8 * (Partially) defined what it means to `reprify` a term.
9 * Clarified some matters as implementation-defined.
710
811 ### modules ###
912
1518
1619 * Virtually full support for user-defined modules. (Not external ones
1720 yet though.)
21 * `tamsin parse` and `tamsin-parser.tamsin` output reprified terms.
1822
1923 0.2
2024 ---
22
33 * `$:deep_reverse`
44 * 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)
67
78 ### more tests ###
89
33 # Note that this may contain support for some features which are not in
44 # the current released or pre-released version.
55
6 main = grammar using scanner.
6 main = (grammar using scanner) → P & $:repr(P).
77
88 grammar = {"@" & pragma & "."} &
99 LM ← nil &
33 # Distributed under a BSD-style license; see LICENSE for more information.
44
55 # 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)
77 # __repr__ : make a string that is valid Python code for constructing the AST
88
9 from tamsin.term import Variable
9 from tamsin.term import Term, Variable
1010
1111
1212 def format_list(l):
1313 if len(l) == 0:
1414 return 'nil'
1515 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:]))
1720
1821
1922 class AST(object):
136139 self.rhs
137140 )
138141
142
139143 class Or(AST):
140144 def __init__(self, lhs, rhs):
141145 self.lhs = lhs
252256 )
253257
254258 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)
259266
260267
261268 class Using(AST):
293300 def __str__(self):
294301 return "fold(%s, %s)" % (
295302 self.rule,
296 self.initial
297 )
303 self.initial.repr()
304 )
189189 def __repr__(self):
190190 return "Variable(%r)" % (self.name)
191191
192 def repr(self):
193 return self.name
194
192195 def match(self, value):
193196 return {self.name: value}