feat: Implement enters operator >> (#8)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
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: #8 Co-Authored-By: Glen Whitney <glen@nobody@nowhere.net> Co-Committed-By: Glen Whitney <glen@nobody@nowhere.net>
This commit is contained in:
parent
527f802793
commit
2e49065031
8 changed files with 100 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
|||
module javascript
|
||||
imports libstrategolib signatures/-
|
||||
imports libstrategolib signatures/- util
|
||||
|
||||
signature
|
||||
constructors
|
||||
|
@ -7,23 +7,25 @@ signature
|
|||
|
||||
rules
|
||||
js: TopLevel(x) -> $[const Stdio = {
|
||||
receives: v => { process.stdout.write(String(v)); return Stdio; }
|
||||
receives: v => { process.stdout.write(String(v)); return Stdio; },
|
||||
}
|
||||
[<js>x]]
|
||||
function forwards(data, strm) {
|
||||
strm.receives(data);
|
||||
return data;
|
||||
}
|
||||
[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>]>
|
||||
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 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>> \)
|
||||
// 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue