fostr/trans/javascript.str
Glen Whitney 2e49065031 feat: Implement enters operator >> (#8)
Also adds parenthesization of fostr expressions.
  Recasts code generation in terms of bottomup processing
  of a local strategy.

  Resolves #1.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Reviewed-on: glen/fostr#8
Co-Authored-By: Glen Whitney <glen@nobody@nowhere.net>
Co-Committed-By: Glen Whitney <glen@nobody@nowhere.net>
2021-02-01 01:46:31 +00:00

34 lines
927 B
Plaintext

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