Autolink during...spawn
This commit is contained in:
parent
666a3daac3
commit
672be25211
|
@ -16,6 +16,7 @@ import {
|
||||||
Binder,
|
Binder,
|
||||||
|
|
||||||
compilePattern,
|
compilePattern,
|
||||||
|
SpawnStatement,
|
||||||
} from './grammar.js';
|
} from './grammar.js';
|
||||||
|
|
||||||
export function stripShebang(items: Items): Items {
|
export function stripShebang(items: Items): Items {
|
||||||
|
@ -138,7 +139,16 @@ export function expand(tree: Items, ctx: ExpansionContext): Items {
|
||||||
// following transformations matters.
|
// following transformations matters.
|
||||||
|
|
||||||
xf(ctx.parser.duringStatement, (s, t) => {
|
xf(ctx.parser.duringStatement, (s, t) => {
|
||||||
// TODO: untyped template
|
let spawn = match(ctx.parser.spawn, s.body, null);
|
||||||
|
if (spawn !== null) {
|
||||||
|
if (spawn.linkedToken !== null) {
|
||||||
|
ctx.emitError(`during ... spawn doesn't need "linked", it's always linked`,
|
||||||
|
spawn.linkedToken);
|
||||||
|
}
|
||||||
|
spawn.linkedToken = getRange(s.body);
|
||||||
|
}
|
||||||
|
let body = (spawn == null) ? walk(s.body) : expandSpawn(spawn, t);
|
||||||
|
|
||||||
const sa = compilePattern(s.pattern);
|
const sa = compilePattern(s.pattern);
|
||||||
return t`assertDataflow(() => ({
|
return t`assertDataflow(() => ({
|
||||||
target: currentSyndicateTarget,
|
target: currentSyndicateTarget,
|
||||||
|
@ -148,7 +158,7 @@ export function expand(tree: Items, ctx: ExpansionContext): Items {
|
||||||
(${ctx.argDecl(t, '__vs', '__SYNDICATE__.AnyValue')}) => {
|
(${ctx.argDecl(t, '__vs', '__SYNDICATE__.AnyValue')}) => {
|
||||||
if (Array.isArray(__vs)) {
|
if (Array.isArray(__vs)) {
|
||||||
${joinItems(sa.captureBinders.map(binderTypeGuard(ctx, t)), '\n')}
|
${joinItems(sa.captureBinders.map(binderTypeGuard(ctx, t)), '\n')}
|
||||||
${walk(s.body)}
|
${body}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
|
@ -156,17 +166,18 @@ ${joinItems(sa.captureBinders.map(binderTypeGuard(ctx, t)), '\n')}
|
||||||
}));`;
|
}));`;
|
||||||
});
|
});
|
||||||
|
|
||||||
xf(ctx.parser.spawn, (s, t) => {
|
function expandSpawn(spawn: SpawnStatement, t: TemplateFunction): Items {
|
||||||
// TODO: parentBinders, parentInits
|
// TODO: parentBinders, parentInits
|
||||||
let body = walk(s.body);
|
|
||||||
/*
|
/*
|
||||||
let assertions = (s.initialAssertions.length > 0)
|
let assertions = (s.initialAssertions.length > 0)
|
||||||
? t`, new __SYNDICATE__.Set([${commaJoin(s.initialAssertions.map(walk))}])`
|
? t`, new __SYNDICATE__.Set([${commaJoin(s.initialAssertions.map(walk))}])`
|
||||||
: ``;
|
: ``;
|
||||||
*/
|
*/
|
||||||
const n = s.name === void 0 ? '' : t` __SYNDICATE__.Turn.activeFacet.actor.name = ${walk(s.name)};`;
|
const n = spawn.name === void 0 ? '' : t` __SYNDICATE__.Turn.activeFacet.actor.name = ${walk(spawn.name)};`;
|
||||||
return t`_spawn${s.isLink ? 'Link': ''}(() => {${n} ${body} });`;
|
return t`_spawn${spawn.linkedToken ? 'Link': ''}(() => {${n} ${walk(spawn.body)} });`;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
xf(ctx.parser.spawn, expandSpawn);
|
||||||
|
|
||||||
x(ctx.parser.fieldDeclarationStatement, (s, t) => {
|
x(ctx.parser.fieldDeclarationStatement, (s, t) => {
|
||||||
const ft = ctx.typescript ? t`<${s.field.type ?? '__SYNDICATE__.AnyValue'}>` : '';
|
const ft = ctx.typescript ? t`<${s.field.type ?? '__SYNDICATE__.AnyValue'}>` : '';
|
||||||
|
|
|
@ -30,7 +30,7 @@ export interface FacetSetupAction extends TurnAction {
|
||||||
|
|
||||||
export interface SpawnStatement extends FacetSetupAction {
|
export interface SpawnStatement extends FacetSetupAction {
|
||||||
name?: Expr;
|
name?: Expr;
|
||||||
isLink: boolean;
|
linkedToken: TokenBase | null;
|
||||||
parentBinders: Binder[];
|
parentBinders: Binder[];
|
||||||
parentInits: Expr[];
|
parentInits: Expr[];
|
||||||
}
|
}
|
||||||
|
@ -207,12 +207,12 @@ export class SyndicateParser {
|
||||||
// Principal: Turn
|
// Principal: Turn
|
||||||
readonly spawn: Pattern<SpawnStatement> =
|
readonly spawn: Pattern<SpawnStatement> =
|
||||||
this.turnAction(o => {
|
this.turnAction(o => {
|
||||||
o.isLink = false;
|
o.linkedToken = null;
|
||||||
o.parentBinders = [];
|
o.parentBinders = [];
|
||||||
o.parentInits = [];
|
o.parentInits = [];
|
||||||
o.body = [];
|
o.body = [];
|
||||||
return seq(atom('spawn'),
|
return seq(atom('spawn'),
|
||||||
option(map(atom('linked'), _ => o.isLink = true)),
|
option(map(atom('linked'), tok => o.linkedToken = tok)),
|
||||||
option(seq(atom('named'), bind(o, 'name', this.headerExpr))),
|
option(seq(atom('named'), bind(o, 'name', this.headerExpr))),
|
||||||
repeat(alt(
|
repeat(alt(
|
||||||
/* seq(kw('asserting'), map(this.headerExpr, e => o.initialAssertions.push(e))), */
|
/* seq(kw('asserting'), map(this.headerExpr, e => o.initialAssertions.push(e))), */
|
||||||
|
|
Loading…
Reference in New Issue