2021-01-30 23:37:53 +00:00
|
|
|
module python
|
2021-02-01 01:46:31 +00:00
|
|
|
imports libstrategolib signatures/- util
|
2021-01-30 23:37:53 +00:00
|
|
|
|
|
|
|
signature
|
|
|
|
constructors
|
|
|
|
TopLevel: Ex -> Ex
|
|
|
|
|
|
|
|
rules
|
2021-02-01 01:46:31 +00:00
|
|
|
|
2021-01-30 23:37:53 +00:00
|
|
|
py: TopLevel(x) -> $[import sys
|
|
|
|
class StdioC:
|
|
|
|
def receives(self, v):
|
|
|
|
print(v, file=sys.stdout, end='')
|
|
|
|
return self
|
2021-02-01 01:46:31 +00:00
|
|
|
def forwards(data,strm):
|
|
|
|
strm.receives(data)
|
|
|
|
return data
|
2021-01-30 23:37:53 +00:00
|
|
|
Stdio = StdioC()
|
2021-02-01 01:46:31 +00:00
|
|
|
[x]]
|
2021-01-30 23:37:53 +00:00
|
|
|
|
|
|
|
py: Stdio() -> $[Stdio]
|
|
|
|
py: Int(x) -> x
|
2021-02-01 01:46:31 +00:00
|
|
|
py: Sum(x) -> $[sum([x])]
|
|
|
|
py: Receives(x, y) -> $[[x].receives([y])]
|
|
|
|
py: Enters(x, y) -> $[forwards([x],[y])]
|
|
|
|
|
|
|
|
pylist: x -> $<[<<join(|", ")>x>]>
|
2021-01-30 23:37:53 +00:00
|
|
|
|
|
|
|
strategies
|
|
|
|
|
2021-02-01 01:46:31 +00:00
|
|
|
// wrap with a toplevel, then generate code from the bottom up
|
|
|
|
python = !TopLevel(<id>); bottomup(try(py <+ pylist))
|
2021-01-30 23:37:53 +00:00
|
|
|
|
|
|
|
// 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
|