fostr/trans/javascript.str

30 lines
782 B
Plaintext
Raw Normal View History

module javascript
imports libstrategolib signatures/- util
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: Terminate(x) -> x
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