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() [x]] py: Stdio() -> $[Stdio] py: Int(x) -> x py: Sum(x) -> $[sum([x])] py: Receives(x, y) -> $[[x].receives([y])] py: [] -> $<[]> py: [x | xs] -> $<[<x><xs>]> strategies // wrap expression in a toplevel and then apply code generation python = !TopLevel(); py // translate each element of a list, prepending each with ',', and concatenate pytail = foldr(!"", \ (x,y) -> $[, [x][y]] \) // Interface python code generation with editor services and file system to-python: (selected, _, _, path, project-path) -> (filename, result) with filename := path ; result := selected