Glen Whitney
904f651897
All checks were successful
continuous-integration/drone/push Build is passing
Also rudimentary code generation. The difficulty is that for Haskell generation, we need to know whether an expression is a string or in to send it to standard output. So we will need to begin implementation of a type system for fostr.
33 lines
826 B
Plaintext
33 lines
826 B
Plaintext
module python
|
|
imports libstrategolib signatures/- util
|
|
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: LitString(x) -> $[r'[x]']
|
|
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
|
|
|
|
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
|