fostr/trans/javascript.str

33 lines
786 B
Plaintext

module javascript
imports libstrategolib signatures/- util
signature
constructors
TopLevel: Ex -> Ex
rules
js: TopLevel(x) -> $[const Stdio = {
gets: v => { process.stdout.write(String(v)); return Stdio; },
}
function to(data, strm) {
strm.gets(data);
return data;
}
[x]]
js: Stream() -> $[Stdio]
js: Int(x) -> x
js: Sum(x,y) -> $[[x] + [y]]
js: Gets(x, y) -> $[[x].gets([y])]
js: To(x, y) -> $[to([x],[y])]
js: Sequence(l) -> <join(|";\n")>l
strategies
javascript = bottomup(try(js))
// Interface javascript code generation with editor services and file system
to-javascript: (selected, _, _, path, project-path) -> (filename, result)
with filename := <guarantee-extension(|"js")> path
; result := <javascript> selected