fostr/trans/python.str

37 lines
833 B
Plaintext
Raw Permalink Normal View History

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(data,strm):
strm.receives(data)
return data
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) -> $[forwards([x],[y])]
pylist: x -> $<[<<join(|", ")>x>]>
strategies
python = 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