fostr/trans/javascript.str
Glen Whitney 7b00b01856
All checks were successful
continuous-integration/drone/push Build is passing
chore: Switch to this repository from predecessor
2021-01-30 15:37:53 -08:00

32 lines
942 B
Plaintext

module javascript
imports libstrategolib signatures/-
signature
constructors
TopLevel: Ex -> Ex
rules
js: TopLevel(x) -> $[const Stdio = {
receives: v => { process.stdout.write(String(v)); return Stdio; }
}
[<js>x]]
js: Stdio() -> $[Stdio]
js: Int(x) -> x
js: Sum(x) -> $[[<js>x].reduce((v,w) => v+w)]
js: Receives(x, y) -> $[[<js>x].receives([<js>y])]
js: [] -> $<[]>
js: [x | xs] -> $<[<<js>x><<jstail>xs>]>
strategies
// wrap expression in a toplevel and then apply code generation
javascript = !TopLevel(<id>); js
// translate each element of a list, prepending each with ',', and concatenate
jstail = foldr(!"", \ (x,y) -> $<, <<js>x><y>> \)
// 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