fostr/trans/python.str
Glen Whitney 7b00b01856
All checks were successful
continuous-integration/drone/push Build is passing
chore: Switch to this repository from predecessor
2021-01-30 15:37:53 -08:00

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