Glen Whitney
7b00b01856
All checks were successful
continuous-integration/drone/push Build is passing
35 lines
947 B
Plaintext
35 lines
947 B
Plaintext
module python
|
|
imports libstrategolib signatures/-
|
|
|
|
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
|
|
Stdio = StdioC()
|
|
[<py>x]]
|
|
|
|
py: Stdio() -> $[Stdio]
|
|
py: Int(x) -> x
|
|
py: Sum(x) -> $[sum([<py>x])]
|
|
py: Receives(x, y) -> $[[<py>x].receives([<py>y])]
|
|
py: [] -> $<[]>
|
|
py: [x | xs] -> $<[<<py>x><<pytail>xs>]>
|
|
|
|
strategies
|
|
// wrap expression in a toplevel and then apply code generation
|
|
python = !TopLevel(<id>); py
|
|
|
|
// translate each element of a list, prepending each with ',', and concatenate
|
|
pytail = foldr(!"", \ (x,y) -> $[, [<py>x][y]] \)
|
|
|
|
// 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
|