feat: add <<< and >>> abbreviating operations to default stream
Resolves #16.
This commit is contained in:
parent
2772fd0c5c
commit
7d4d3b93c9
8 changed files with 37 additions and 12 deletions
|
@ -15,7 +15,9 @@ rules
|
|||
|
||||
seqFlatten: Sequence(l) -> Sequence(<mapconcat(?Sequence(<id>) <+ ![<id>])>l)
|
||||
|
||||
defStream: DefGets(x) -> Gets(Stream(), x)
|
||||
defStream: DefTo(x) -> To(x, Stream())
|
||||
|
||||
strategies
|
||||
|
||||
desugar-fostr = bottomup(try(deISe <+ seqFlatten))
|
||||
|
||||
desugar-fostr = bottomup(try(defStream <+ deISe <+ seqFlatten))
|
||||
|
|
|
@ -19,7 +19,8 @@ rules
|
|||
returning the final value.
|
||||
*/
|
||||
|
||||
hs: (_, TopLevel(val)) -> $[import System.IO
|
||||
hs: (_, TopLevel(val)) -> $[-- Preamble from fostr
|
||||
import System.IO
|
||||
data IOStream = StdIO
|
||||
|
||||
gets :: Show b => a -> b -> IO a
|
||||
|
|
|
@ -2,13 +2,16 @@ module javascript
|
|||
imports libstrategolib signatures/- util
|
||||
|
||||
rules
|
||||
js: TopLevel(x) -> $[const Stdio = {
|
||||
js: TopLevel(x) -> $[// Fostr preamble
|
||||
const Stdio = {
|
||||
gets: v => { process.stdout.write(String(v)); return Stdio; },
|
||||
}
|
||||
function to(data, strm) {
|
||||
strm.gets(data);
|
||||
return data;
|
||||
}
|
||||
// End of preamble
|
||||
|
||||
[x]]
|
||||
|
||||
js: Stream() -> $[Stdio]
|
||||
|
|
|
@ -2,7 +2,8 @@ module python
|
|||
imports libstrategolib signatures/- util
|
||||
rules
|
||||
|
||||
py: TopLevel(x) -> $[import sys
|
||||
py: TopLevel(x) -> $[## Fostr preamble
|
||||
import sys
|
||||
class StdioC:
|
||||
def gets(self, v):
|
||||
print(v, file=sys.stdout, end='')
|
||||
|
@ -11,6 +12,8 @@ rules
|
|||
strm.gets(data)
|
||||
return data
|
||||
Stdio = StdioC()
|
||||
## End of preamble
|
||||
|
||||
[x]]
|
||||
|
||||
py: Stream() -> $[Stdio]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue