Glen Whitney
7feddbcfbe
All checks were successful
continuous-integration/drone/push Build is passing
Add the ! postfix operator and !! expression. Also add the ++ string concatenation operator. Also allow specification of standard input in the test scheme. Resolves #7, #18. Co-authored-by: Glen Whitney <glen@studioinfinity.org> Reviewed-on: #25 Co-Authored-By: Glen Whitney <glen@nobody@nowhere.net> Co-Committed-By: Glen Whitney <glen@nobody@nowhere.net>
41 lines
1.0 KiB
Plaintext
41 lines
1.0 KiB
Plaintext
module python
|
|
imports libstrategolib signatures/- util
|
|
rules
|
|
|
|
py: TopLevel(x) -> $[## Fostr preamble
|
|
import sys
|
|
class StdioC:
|
|
def gets(self, v):
|
|
print(v, file=sys.stdout, end='')
|
|
return self
|
|
def emit(self):
|
|
return input() + "\n" # Python inconsistently strips when using input
|
|
def to(data,strm):
|
|
strm.gets(data)
|
|
return data
|
|
Stdio = StdioC()
|
|
## End of preamble
|
|
|
|
[x]]
|
|
|
|
py: Stream() -> $[Stdio]
|
|
py: Int(x) -> x
|
|
py: LitString(x) -> $[r[x]]
|
|
py: EscString(x) -> x
|
|
py: Sum(x,y) -> $[[x] + [y]]
|
|
py: Concat(x,y) -> $[[x] + [y]]
|
|
py: Gets(x, y) -> $[[x].gets([y])]
|
|
py: To(x, y) -> $[to([x],[y])]
|
|
py: Emits(x) -> $[[x].emit()]
|
|
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
|