fostr/trans/python.str
Glen Whitney 991976d3a8 feat: sequencing of expressions with newline to same indent (#11)
feat: sequencing of expressions with newline to same indent

  Also revised README to reflect greater emphasis on streams.
  Haskell code generation unsurprisingly required a fairly significant
  rework.

  Resolves #3.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Reviewed-on: glen/fostr#11
Co-Authored-By: Glen Whitney <glen@nobody@nowhere.net>
Co-Committed-By: Glen Whitney <glen@nobody@nowhere.net>
2021-02-06 05:11:41 +00:00

36 lines
808 B
Plaintext

module python
imports libstrategolib signatures/- util
signature
constructors
TopLevel: Ex -> Ex
rules
py: TopLevel(x) -> $[import sys
class StdioC:
def gets(self, v):
print(v, file=sys.stdout, end='')
return self
def to(data,strm):
strm.gets(data)
return data
Stdio = StdioC()
[x]]
py: Stream() -> $[Stdio]
py: Int(x) -> x
py: Sum(x,y) -> $[[x] + [y]]
py: Gets(x, y) -> $[[x].gets([y])]
py: To(x, y) -> $[to([x],[y])]
py: Sequence(l) -> <join(|"\n")>l
strategies
python = bottomup(try(py))
// 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