forked from glen/fostr
Glen Whitney
a564b2274d
Also added paranthesization of fostr expressions. Finally managed to cast code generation in terms of bottomup processing of a local strategy. Resolves #1.
38 lines
913 B
Plaintext
38 lines
913 B
Plaintext
module python
|
|
imports libstrategolib signatures/- util
|
|
|
|
signature
|
|
constructors
|
|
TopLevel: Ex -> Ex
|
|
|
|
rules
|
|
|
|
py: TopLevel(x) -> $[import sys
|
|
class StdioC:
|
|
def receives(self, v):
|
|
print(v, file=sys.stdout, end='')
|
|
return self
|
|
def forwards(self, v):
|
|
self.receives(v)
|
|
return v
|
|
Stdio = StdioC()
|
|
[x]]
|
|
|
|
py: Stdio() -> $[Stdio]
|
|
py: Int(x) -> x
|
|
py: Sum(x) -> $[sum([x])]
|
|
py: Receives(x, y) -> $[[x].receives([y])]
|
|
py: Enters(x, y) -> $[[y].forwards([x])]
|
|
|
|
pylist: x -> $<[<<join(|", ")>x>]>
|
|
|
|
strategies
|
|
|
|
// wrap with a toplevel, then generate code from the bottom up
|
|
python = !TopLevel(<id>); bottomup(try(py <+ pylist))
|
|
|
|
// Interface python code generation with editor services and file system
|
|
to-python: (selected, _, _, path, project-path) -> (filename, result)
|
|
with filename := <guarantee-extension(|"py")> path
|
|
; result := <python> selected
|