2021-01-30 23:37:53 +00:00
|
|
|
module javascript
|
2021-02-01 00:44:45 +00:00
|
|
|
imports libstrategolib signatures/- util
|
2021-01-30 23:37:53 +00:00
|
|
|
|
|
|
|
signature
|
|
|
|
constructors
|
|
|
|
TopLevel: Ex -> Ex
|
|
|
|
|
|
|
|
rules
|
|
|
|
js: TopLevel(x) -> $[const Stdio = {
|
2021-02-01 00:44:45 +00:00
|
|
|
receives: v => { process.stdout.write(String(v)); return Stdio; },
|
2021-02-01 01:24:40 +00:00
|
|
|
}
|
|
|
|
function forwards(data, strm) {
|
|
|
|
strm.receives(data);
|
|
|
|
return data;
|
2021-01-30 23:37:53 +00:00
|
|
|
}
|
2021-02-01 00:44:45 +00:00
|
|
|
[x]]
|
2021-01-30 23:37:53 +00:00
|
|
|
|
|
|
|
js: Stdio() -> $[Stdio]
|
|
|
|
js: Int(x) -> x
|
2021-02-01 00:44:45 +00:00
|
|
|
js: Sum(x) -> $[[x].reduce((v,w) => v+w)]
|
|
|
|
js: Receives(x, y) -> $[[x].receives([y])]
|
2021-02-01 01:24:40 +00:00
|
|
|
js: Enters(x, y) -> $[forwards([x],[y])]
|
2021-01-30 23:37:53 +00:00
|
|
|
|
2021-02-01 00:44:45 +00:00
|
|
|
jslist: x -> $<[<<join(|", ")>x>]>
|
2021-01-30 23:37:53 +00:00
|
|
|
|
2021-02-01 00:44:45 +00:00
|
|
|
strategies
|
|
|
|
// wrap expression in a toplevel, then generate code from bottom up
|
|
|
|
javascript = !TopLevel(<id>); bottomup(try(js <+ jslist))
|
2021-01-30 23:37:53 +00:00
|
|
|
|
|
|
|
// 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
|