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
|
|
|
rules
|
2021-02-01 01:46:31 +00:00
|
|
|
|
2021-01-30 23:37:53 +00:00
|
|
|
py: TopLevel(x) -> $[import sys
|
|
|
|
class StdioC:
|
2021-02-06 05:11:41 +00:00
|
|
|
def gets(self, v):
|
2021-01-30 23:37:53 +00:00
|
|
|
print(v, file=sys.stdout, end='')
|
|
|
|
return self
|
2021-02-06 05:11:41 +00:00
|
|
|
def to(data,strm):
|
|
|
|
strm.gets(data)
|
2021-02-01 01:46:31 +00:00
|
|
|
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
|
|
|
|
2021-02-10 20:47:34 +00:00
|
|
|
py: Stream() -> $[Stdio]
|
|
|
|
py: Int(x) -> x
|
2021-02-18 04:17:05 +00:00
|
|
|
py: LitString(x) -> $[r[x]]
|
2021-02-10 20:47:34 +00:00
|
|
|
py: Sum(x,y) -> $[[x] + [y]]
|
|
|
|
py: Gets(x, y) -> $[[x].gets([y])]
|
|
|
|
py: To(x, y) -> $[to([x],[y])]
|
|
|
|
py: Terminate(x) -> $[[x];]
|
|
|
|
py: Sequence(l) -> <join(|"\n")>l
|
2021-01-30 23:37:53 +00:00
|
|
|
|
|
|
|
strategies
|
|
|
|
|
2021-02-06 05:11:41 +00:00
|
|
|
python = bottomup(try(py))
|
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
|