forked from glen/fostr
Glen Whitney
a564b2274d
Also added paranthesization of fostr expressions. Finally managed to cast code generation in terms of bottomup processing of a local strategy. Resolves #1.
31 lines
913 B
Plaintext
31 lines
913 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; },
|
|
forwards: v => { process.stdout.write(String(v)); return v; }
|
|
}
|
|
[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) -> $[[y].forwards([x])]
|
|
|
|
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
|