Add syntax for sync. Closes #6
This commit is contained in:
parent
d14ddc39f7
commit
81696a90b4
|
@ -328,6 +328,8 @@ ${joinItems(sa.captureBinders.map(binderTypeGuard(t)), '\n')}
|
||||||
|
|
||||||
x(ctx.parser.stopStatement, (s, t) => t`${terminalWrap(t, s.facetToStop, s.body)};`);
|
x(ctx.parser.stopStatement, (s, t) => t`${terminalWrap(t, s.facetToStop, s.body)};`);
|
||||||
|
|
||||||
|
xf(ctx.parser.syncStatement, (s, t) => t`_sync(${walk(s.peerToSyncWith)}, __SYNDICATE__.Turn.ref({ message() {${walk(s.body)}} }));`);
|
||||||
|
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,10 @@ export interface StopStatement extends StatementTurnAction {
|
||||||
facetToStop: FacetToStop;
|
facetToStop: FacetToStop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SyncStatement extends StatementTurnAction {
|
||||||
|
peerToSyncWith: Expr;
|
||||||
|
}
|
||||||
|
|
||||||
export interface GenericEventEndpointStatement extends StatementTurnAction {
|
export interface GenericEventEndpointStatement extends StatementTurnAction {
|
||||||
facetToStop: FacetToStop | 'none' | 'once-wrapper';
|
facetToStop: FacetToStop | 'none' | 'once-wrapper';
|
||||||
once: boolean;
|
once: boolean;
|
||||||
|
@ -385,6 +389,15 @@ export class SyndicateParser {
|
||||||
alt(this.block(o.body), this.statementBoundary));
|
alt(this.block(o.body), this.statementBoundary));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Principal: Turn
|
||||||
|
readonly syncStatement: Pattern<SyncStatement> =
|
||||||
|
this.turnAction(o => {
|
||||||
|
o.body = [];
|
||||||
|
return seq(atom('sync'),
|
||||||
|
map(this.expr1(), e => o.peerToSyncWith = e),
|
||||||
|
this.block(o.body));
|
||||||
|
});
|
||||||
|
|
||||||
// Principal: none
|
// Principal: none
|
||||||
readonly atStatement: Pattern<AtStatement> =
|
readonly atStatement: Pattern<AtStatement> =
|
||||||
scope(o => {
|
scope(o => {
|
||||||
|
|
|
@ -46,6 +46,21 @@ __SYNDICATE__.Turn.active.facet(() => {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('sync', () => {
|
||||||
|
it('empty body', () => expectCodeEqual(`sync p {}`, `
|
||||||
|
__SYNDICATE__.Turn.active._sync(p, __SYNDICATE__.Turn.ref({
|
||||||
|
message() {}
|
||||||
|
}));`));
|
||||||
|
|
||||||
|
it('nonempty body', () => expectCodeEqual(`sync p {q(); r();}`, `
|
||||||
|
__SYNDICATE__.Turn.active._sync(p, __SYNDICATE__.Turn.ref({
|
||||||
|
message() {
|
||||||
|
q();
|
||||||
|
r();
|
||||||
|
}
|
||||||
|
}));`));
|
||||||
|
});
|
||||||
|
|
||||||
describe('spawn', () => {
|
describe('spawn', () => {
|
||||||
|
|
||||||
it('without name', () => expectCodeEqual(`spawn { a; b; c; }`, `
|
it('without name', () => expectCodeEqual(`spawn { a; b; c; }`, `
|
||||||
|
|
Loading…
Reference in New Issue