@patterkit/dialect 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ ENGINE_SCOPES: () => ENGINE_SCOPES,
24
+ EXTERNAL_SCOPES: () => EXTERNAL_SCOPES,
23
25
  buildSchema: () => buildSchema,
24
26
  dialectWithForeignScopes: () => dialectWithForeignScopes,
25
27
  extractSlots: () => extractSlots,
@@ -28,9 +30,18 @@ __export(index_exports, {
28
30
  patterDialect: () => patterDialect,
29
31
  renderSlotValue: () => renderSlotValue,
30
32
  splitRef: () => splitRef,
31
- stripCaptions: () => stripCaptions
33
+ stripCaptions: () => stripCaptions,
34
+ withEngineScopes: () => withEngineScopes
32
35
  });
33
36
  module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/engine-scopes.ts
39
+ var ENGINE_SCOPES = [
40
+ { token: "patter", engine: "Patterplay", means: "Patter's shared globals" },
41
+ { token: "story", engine: "Storylet Engine", means: "the Storylet Engine's shared @story properties" }
42
+ ];
43
+
44
+ // src/index.ts
34
45
  var import_expr = require("@wildwinter/expr");
35
46
  function host(h) {
36
47
  return h.ctx.host ?? {};
@@ -128,8 +139,15 @@ var patterDialect = {
128
139
  }
129
140
  }
130
141
  };
131
- function dialectWithForeignScopes(spec) {
132
- if (!spec || spec.scopes.length === 0) return patterDialect;
142
+ var EXTERNAL_SCOPES = ENGINE_SCOPES.map((s) => s.token).filter((t) => t !== "patter" && t !== "scene");
143
+ function withEngineScopes(spec) {
144
+ const present = new Set((spec?.scopes ?? []).map((s) => s.token));
145
+ const extra = EXTERNAL_SCOPES.filter((t) => !present.has(t)).map((token) => ({ token }));
146
+ return { version: spec?.version ?? 1, scopes: [...spec?.scopes ?? [], ...extra] };
147
+ }
148
+ function dialectWithForeignScopes(given) {
149
+ const spec = withEngineScopes(given);
150
+ if (spec.scopes.length === 0) return patterDialect;
133
151
  const known = new Set(patterDialect.scopes.map((s) => s.token));
134
152
  const extra = spec.scopes.filter((s) => !known.has(s.token)).map((s) => ({ token: s.token }));
135
153
  if (extra.length === 0) return patterDialect;
@@ -363,6 +381,8 @@ function interpolate(text, resolve) {
363
381
  }
364
382
  // Annotate the CommonJS export names for ESM import in node:
365
383
  0 && (module.exports = {
384
+ ENGINE_SCOPES,
385
+ EXTERNAL_SCOPES,
366
386
  buildSchema,
367
387
  dialectWithForeignScopes,
368
388
  extractSlots,
@@ -371,5 +391,6 @@ function interpolate(text, resolve) {
371
391
  patterDialect,
372
392
  renderSlotValue,
373
393
  splitRef,
374
- stripCaptions
394
+ stripCaptions,
395
+ withEngineScopes
375
396
  });
package/dist/index.d.cts CHANGED
@@ -2,8 +2,34 @@ import { ExpressionSchema, Dialect, ScalarValue } from '@wildwinter/expr';
2
2
  import { ScopeRegistrySpec } from '@wildwinter/scoperegistry';
3
3
  import { ProjectFile, PropertyDecl, HostScopeRegistry } from '@patterkit/model';
4
4
 
5
+ /** Every engine's game-wide scope token across the family. A compiler accepts every token here
6
+ * that is not its own engine's, unchecked: the other engine owns those names and types. */
7
+ interface EngineScope {
8
+ token: string;
9
+ engine: string;
10
+ means: string;
11
+ }
12
+ declare const ENGINE_SCOPES: readonly EngineScope[];
13
+
5
14
  /** The Patter dialect: scopes patter/scene + built-in functions. */
6
15
  declare const patterDialect: Dialect;
16
+ /**
17
+ * Other engines' game-wide scopes a Patter expression may name, from the family's
18
+ * shared list (expr/family/engine-scopes.json): `@story.act` reads the Storylet
19
+ * Engine's shared @story in a game that runs both. On by default, with no project
20
+ * setting, so combining the engines needs no wiring. They are opaque here (the
21
+ * other engine owns their names and types), never self-backed, and the engine
22
+ * reports at run time when the game has not registered one.
23
+ */
24
+ declare const EXTERNAL_SCOPES: readonly string[];
25
+ /**
26
+ * A foreign-scope spec with the family's other engines added as OPAQUE scopes
27
+ * (no declarations), unless the spec already declares them: a project that
28
+ * imported the Storylet Engine's spec keeps its checked declarations. For
29
+ * compiling and validating only; a bundle's own scopeRegistry never carries
30
+ * these, because the runtime self-backs what it lists.
31
+ */
32
+ declare function withEngineScopes(spec?: ScopeRegistrySpec): ScopeRegistrySpec;
7
33
  /**
8
34
  * A Patter dialect extended with FOREIGN scope tokens imported from another
9
35
  * owner's `scopeRegistrySpec` (e.g. a storylet's `@world` / `@player` / `@system`).
@@ -12,7 +38,7 @@ declare const patterDialect: Dialect;
12
38
  * Foreign scopes use the default missing policy (graceful-false). With no spec
13
39
  * (or an empty one) this returns the base `patterDialect` unchanged.
14
40
  */
15
- declare function dialectWithForeignScopes(spec?: ScopeRegistrySpec): Dialect;
41
+ declare function dialectWithForeignScopes(given?: ScopeRegistrySpec): Dialect;
16
42
  /**
17
43
  * Split a property ref ("@name" / "@scope.name") into scope + name - THE one
18
44
  * ref grammar, shared by the compiler's validators and the runtime so they
@@ -81,4 +107,4 @@ declare function stripCaptions(text: string, open: string, close: string): strin
81
107
  */
82
108
  declare function interpolate(text: string, resolve: (ref: string) => ScalarValue | undefined): string;
83
109
 
84
- export { type Slot, buildSchema, dialectWithForeignScopes, extractSlots, hostScopesToSpec, interpolate, patterDialect, renderSlotValue, splitRef, stripCaptions };
110
+ export { ENGINE_SCOPES, EXTERNAL_SCOPES, type EngineScope, type Slot, buildSchema, dialectWithForeignScopes, extractSlots, hostScopesToSpec, interpolate, patterDialect, renderSlotValue, splitRef, stripCaptions, withEngineScopes };
package/dist/index.d.ts CHANGED
@@ -2,8 +2,34 @@ import { ExpressionSchema, Dialect, ScalarValue } from '@wildwinter/expr';
2
2
  import { ScopeRegistrySpec } from '@wildwinter/scoperegistry';
3
3
  import { ProjectFile, PropertyDecl, HostScopeRegistry } from '@patterkit/model';
4
4
 
5
+ /** Every engine's game-wide scope token across the family. A compiler accepts every token here
6
+ * that is not its own engine's, unchecked: the other engine owns those names and types. */
7
+ interface EngineScope {
8
+ token: string;
9
+ engine: string;
10
+ means: string;
11
+ }
12
+ declare const ENGINE_SCOPES: readonly EngineScope[];
13
+
5
14
  /** The Patter dialect: scopes patter/scene + built-in functions. */
6
15
  declare const patterDialect: Dialect;
16
+ /**
17
+ * Other engines' game-wide scopes a Patter expression may name, from the family's
18
+ * shared list (expr/family/engine-scopes.json): `@story.act` reads the Storylet
19
+ * Engine's shared @story in a game that runs both. On by default, with no project
20
+ * setting, so combining the engines needs no wiring. They are opaque here (the
21
+ * other engine owns their names and types), never self-backed, and the engine
22
+ * reports at run time when the game has not registered one.
23
+ */
24
+ declare const EXTERNAL_SCOPES: readonly string[];
25
+ /**
26
+ * A foreign-scope spec with the family's other engines added as OPAQUE scopes
27
+ * (no declarations), unless the spec already declares them: a project that
28
+ * imported the Storylet Engine's spec keeps its checked declarations. For
29
+ * compiling and validating only; a bundle's own scopeRegistry never carries
30
+ * these, because the runtime self-backs what it lists.
31
+ */
32
+ declare function withEngineScopes(spec?: ScopeRegistrySpec): ScopeRegistrySpec;
7
33
  /**
8
34
  * A Patter dialect extended with FOREIGN scope tokens imported from another
9
35
  * owner's `scopeRegistrySpec` (e.g. a storylet's `@world` / `@player` / `@system`).
@@ -12,7 +38,7 @@ declare const patterDialect: Dialect;
12
38
  * Foreign scopes use the default missing policy (graceful-false). With no spec
13
39
  * (or an empty one) this returns the base `patterDialect` unchanged.
14
40
  */
15
- declare function dialectWithForeignScopes(spec?: ScopeRegistrySpec): Dialect;
41
+ declare function dialectWithForeignScopes(given?: ScopeRegistrySpec): Dialect;
16
42
  /**
17
43
  * Split a property ref ("@name" / "@scope.name") into scope + name - THE one
18
44
  * ref grammar, shared by the compiler's validators and the runtime so they
@@ -81,4 +107,4 @@ declare function stripCaptions(text: string, open: string, close: string): strin
81
107
  */
82
108
  declare function interpolate(text: string, resolve: (ref: string) => ScalarValue | undefined): string;
83
109
 
84
- export { type Slot, buildSchema, dialectWithForeignScopes, extractSlots, hostScopesToSpec, interpolate, patterDialect, renderSlotValue, splitRef, stripCaptions };
110
+ export { ENGINE_SCOPES, EXTERNAL_SCOPES, type EngineScope, type Slot, buildSchema, dialectWithForeignScopes, extractSlots, hostScopesToSpec, interpolate, patterDialect, renderSlotValue, splitRef, stripCaptions, withEngineScopes };
package/dist/index.js CHANGED
@@ -1,3 +1,9 @@
1
+ // src/engine-scopes.ts
2
+ var ENGINE_SCOPES = [
3
+ { token: "patter", engine: "Patterplay", means: "Patter's shared globals" },
4
+ { token: "story", engine: "Storylet Engine", means: "the Storylet Engine's shared @story properties" }
5
+ ];
6
+
1
7
  // src/index.ts
2
8
  import { EvalError } from "@wildwinter/expr";
3
9
  function host(h) {
@@ -96,8 +102,15 @@ var patterDialect = {
96
102
  }
97
103
  }
98
104
  };
99
- function dialectWithForeignScopes(spec) {
100
- if (!spec || spec.scopes.length === 0) return patterDialect;
105
+ var EXTERNAL_SCOPES = ENGINE_SCOPES.map((s) => s.token).filter((t) => t !== "patter" && t !== "scene");
106
+ function withEngineScopes(spec) {
107
+ const present = new Set((spec?.scopes ?? []).map((s) => s.token));
108
+ const extra = EXTERNAL_SCOPES.filter((t) => !present.has(t)).map((token) => ({ token }));
109
+ return { version: spec?.version ?? 1, scopes: [...spec?.scopes ?? [], ...extra] };
110
+ }
111
+ function dialectWithForeignScopes(given) {
112
+ const spec = withEngineScopes(given);
113
+ if (spec.scopes.length === 0) return patterDialect;
101
114
  const known = new Set(patterDialect.scopes.map((s) => s.token));
102
115
  const extra = spec.scopes.filter((s) => !known.has(s.token)).map((s) => ({ token: s.token }));
103
116
  if (extra.length === 0) return patterDialect;
@@ -330,6 +343,8 @@ function interpolate(text, resolve) {
330
343
  return out;
331
344
  }
332
345
  export {
346
+ ENGINE_SCOPES,
347
+ EXTERNAL_SCOPES,
333
348
  buildSchema,
334
349
  dialectWithForeignScopes,
335
350
  extractSlots,
@@ -338,5 +353,6 @@ export {
338
353
  patterDialect,
339
354
  renderSlotValue,
340
355
  splitRef,
341
- stripCaptions
356
+ stripCaptions,
357
+ withEngineScopes
342
358
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patterkit/dialect",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "description": "The Patter dialect for @wildwinter/expr (scopes shared/scene/flow, built-in functions), an ExpressionSchema builder from property declarations, and the inline {@ref} interpolation helpers (spec §16).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,8 +34,8 @@
34
34
  "build": "tsup src/index.ts --format esm,cjs --dts --clean"
35
35
  },
36
36
  "dependencies": {
37
- "@patterkit/model": "0.5.0",
37
+ "@patterkit/model": "0.6.0",
38
38
  "@wildwinter/expr": "^0.5.0",
39
- "@wildwinter/scoperegistry": "^0.6.0"
39
+ "@wildwinter/scoperegistry": "^0.7.0"
40
40
  }
41
41
  }