spawn :let ID = INIT :let ID = INIT ... { ... }
This commit is contained in:
parent
51b90071fb
commit
43b5987e8b
1
TODO.md
1
TODO.md
|
@ -5,6 +5,7 @@
|
||||||
- [DONE] `spawn*` or similar - looks like `spawn on start { ... }` will do the trick
|
- [DONE] `spawn*` or similar - looks like `spawn on start { ... }` will do the trick
|
||||||
- [DONE] activation
|
- [DONE] activation
|
||||||
- [DONE] remove ground dataspace syntax
|
- [DONE] remove ground dataspace syntax
|
||||||
|
- [DONE] `spawn :let childVal = parentCalculation { ... }`
|
||||||
|
|
||||||
- `defer` statement
|
- `defer` statement
|
||||||
- `define/query`
|
- `define/query`
|
||||||
|
|
|
@ -32,6 +32,16 @@ export function SpawnStatement(node) {
|
||||||
this.space();
|
this.space();
|
||||||
this.print(a, node);
|
this.print(a, node);
|
||||||
}
|
}
|
||||||
|
for (let i = 0; i < node.parentIds.length; i++) {
|
||||||
|
this.space();
|
||||||
|
this.token(":let");
|
||||||
|
this.space();
|
||||||
|
this.print(node.parentIds[i], node);
|
||||||
|
this.space();
|
||||||
|
this.token("=");
|
||||||
|
this.space();
|
||||||
|
this.print(node.parentInits[i], node);
|
||||||
|
}
|
||||||
this.space();
|
this.space();
|
||||||
this.printBlock(node.bootProc);
|
this.printBlock(node.bootProc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,7 @@ Array.prototype.push.apply(Types.TYPES, Object.keys(Types.DEPRECATED_KEYS));
|
||||||
//
|
//
|
||||||
Types.getBindingIdentifiers.keys.EventHandlerEndpoint = ["captureIds"];
|
Types.getBindingIdentifiers.keys.EventHandlerEndpoint = ["captureIds"];
|
||||||
Types.getBindingIdentifiers.keys.DuringStatement = ["captureIds"];
|
Types.getBindingIdentifiers.keys.DuringStatement = ["captureIds"];
|
||||||
|
Types.getBindingIdentifiers.keys.SpawnStatement = ["parentIds"];
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// (3) Install our modified parser in place of the core parser.
|
// (3) Install our modified parser in place of the core parser.
|
||||||
|
|
|
@ -202,10 +202,24 @@ export default class SyndicateParser extends _original_Parser {
|
||||||
node.name = this.parseExpression();
|
node.name = this.parseExpression();
|
||||||
}
|
}
|
||||||
node.initialAssertions = [];
|
node.initialAssertions = [];
|
||||||
|
node.parentIds = [];
|
||||||
|
node.parentInits = [];
|
||||||
while (this.match(tt.colon)) {
|
while (this.match(tt.colon)) {
|
||||||
this.next();
|
this.next();
|
||||||
this.expectContextual("asserting");
|
if (this.isContextual("asserting")) {
|
||||||
node.initialAssertions.push(this.parseExpression());
|
this.next();
|
||||||
|
node.initialAssertions.push(this.parseExpression());
|
||||||
|
} else if (this.state.type === tt._let) {
|
||||||
|
this.next();
|
||||||
|
const id = this.parseBindingAtom();
|
||||||
|
this.checkLVal(id, true, undefined, "spawn :let declaration");
|
||||||
|
this.expect(tt.eq);
|
||||||
|
const init = this.parseMaybeAssign(false);
|
||||||
|
node.parentIds.push(id);
|
||||||
|
node.parentInits.push(init);
|
||||||
|
} else {
|
||||||
|
this.unexpected();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
node.bootProc = this.parseSyntheticFunctionStatement();
|
node.bootProc = this.parseSyntheticFunctionStatement();
|
||||||
return this.finishNode(node, "SpawnStatement");
|
return this.finishNode(node, "SpawnStatement");
|
||||||
|
|
|
@ -348,6 +348,16 @@ export default declare((api, options) => {
|
||||||
SEQ: t.arrayExpression(node.initialAssertions)
|
SEQ: t.arrayExpression(node.initialAssertions)
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
if (node.parentIds.length > 0) {
|
||||||
|
const stmts = [];
|
||||||
|
for (let i = 0; i < node.parentIds.length; i++) {
|
||||||
|
const id = node.parentIds[i];
|
||||||
|
const init = node.parentInits[i];
|
||||||
|
stmts.push(template(`const ID = INIT;`)({ ID: id, INIT: init }));
|
||||||
|
}
|
||||||
|
stmts.push(path.node);
|
||||||
|
path.replaceWith(t.blockStatement(stmts, []));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
FieldDeclarationStatement(path, state) {
|
FieldDeclarationStatement(path, state) {
|
||||||
|
|
|
@ -25,9 +25,9 @@ import defineType, {
|
||||||
} from "@babel/types/lib/definitions/utils";
|
} from "@babel/types/lib/definitions/utils";
|
||||||
|
|
||||||
defineType("SpawnStatement", {
|
defineType("SpawnStatement", {
|
||||||
builder: ["name", "initialAssertions", "bootProc"],
|
builder: ["name", "initialAssertions", "parentIds", "parentInits", "bootProc"],
|
||||||
visitor: ["name", "initialAssertions", "bootProc"],
|
visitor: ["name", "initialAssertions", "parentIds", "parentInits", "bootProc"],
|
||||||
aliases: ["Statement"],
|
aliases: ["Statement", "Scopable"],
|
||||||
fields: {
|
fields: {
|
||||||
name: {
|
name: {
|
||||||
validate: assertNodeType("Expression"),
|
validate: assertNodeType("Expression"),
|
||||||
|
@ -39,6 +39,12 @@ defineType("SpawnStatement", {
|
||||||
assertEach(assertNodeType("Expression")),
|
assertEach(assertNodeType("Expression")),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
parentIds: {
|
||||||
|
validate: chain(assertValueType("array"), assertEach(assertNodeType("Identifier")),),
|
||||||
|
},
|
||||||
|
parentInits: {
|
||||||
|
validate: chain(assertValueType("array"), assertEach(assertNodeType("Expression")),),
|
||||||
|
},
|
||||||
bootProc: {
|
bootProc: {
|
||||||
validate: assertNodeType("FunctionExpression"),
|
validate: assertNodeType("FunctionExpression"),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue