@sharpee/chord 3.0.0 → 3.3.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/analyzer.d.ts +11 -3
- package/analyzer.d.ts.map +1 -1
- package/analyzer.js +1217 -33
- package/analyzer.js.map +1 -1
- package/ast.d.ts +458 -9
- package/ast.d.ts.map +1 -1
- package/catalog.d.ts +57 -1
- package/catalog.d.ts.map +1 -1
- package/catalog.js +95 -3
- package/catalog.js.map +1 -1
- package/diagnostics.d.ts +1 -1
- package/diagnostics.d.ts.map +1 -1
- package/index.d.ts +31 -13
- package/index.d.ts.map +1 -1
- package/index.js +110 -30
- package/index.js.map +1 -1
- package/ir.d.ts +316 -7
- package/ir.d.ts.map +1 -1
- package/lexer.d.ts +11 -3
- package/lexer.d.ts.map +1 -1
- package/lexer.js +36 -8
- package/lexer.js.map +1 -1
- package/manifests/combat.d.ts +16 -0
- package/manifests/combat.d.ts.map +1 -0
- package/manifests/combat.js +38 -0
- package/manifests/combat.js.map +1 -0
- package/manifests/index.d.ts +21 -0
- package/manifests/index.d.ts.map +1 -0
- package/manifests/index.js +46 -0
- package/manifests/index.js.map +1 -0
- package/manifests/npc.d.ts +19 -0
- package/manifests/npc.d.ts.map +1 -0
- package/manifests/npc.js +38 -0
- package/manifests/npc.js.map +1 -0
- package/manifests/state-machines.d.ts +17 -0
- package/manifests/state-machines.d.ts.map +1 -0
- package/manifests/state-machines.js +8 -0
- package/manifests/state-machines.js.map +1 -0
- package/manifests/types.d.ts +41 -0
- package/manifests/types.d.ts.map +1 -0
- package/manifests/types.js +18 -0
- package/manifests/types.js.map +1 -0
- package/message-alias-catalog.d.ts +22 -0
- package/message-alias-catalog.d.ts.map +1 -0
- package/message-alias-catalog.js +830 -0
- package/message-alias-catalog.js.map +1 -0
- package/package.json +1 -1
- package/parser.d.ts +2 -2
- package/parser.d.ts.map +1 -1
- package/parser.js +1566 -148
- package/parser.js.map +1 -1
- package/phrasebooks.d.ts +28 -0
- package/phrasebooks.d.ts.map +1 -0
- package/phrasebooks.js +6 -0
- package/phrasebooks.js.map +1 -0
package/catalog.d.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* only so the compiler stays platform-free.
|
|
9
9
|
*
|
|
10
10
|
* Public interface: KIND_NOUNS, TRAIT_ADJECTIVES, STATE_ADJECTIVES,
|
|
11
|
-
* PLATFORM_STATE_PAIRS, EVENT_VERBS
|
|
11
|
+
* PLATFORM_STATE_PAIRS, STARTS_STATE_PAIRINGS, EVENT_VERBS,
|
|
12
|
+
* PRONOUN_WORDS, PRONOUN_CASES.
|
|
12
13
|
* Owner context: @sharpee/chord (language frontend; browser-safe).
|
|
13
14
|
* Growing any of these sets is a grammar change — owner approval via
|
|
14
15
|
* docs/architecture/chord-grammar-changes.md.
|
|
@@ -17,6 +18,19 @@
|
|
|
17
18
|
export declare const KIND_NOUNS: ReadonlySet<string>;
|
|
18
19
|
/** v1 trait adjectives (bare, no article). */
|
|
19
20
|
export declare const TRAIT_ADJECTIVES: ReadonlySet<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Standard pronoun sets (ADR-242 D5) — the four rows the lang-{locale}
|
|
23
|
+
* assembler ships. A `pronouns <word>` person line accepts these or a
|
|
24
|
+
* story-defined named set (`define pronouns <name>`); defining a set that
|
|
25
|
+
* shadows one of these is an error.
|
|
26
|
+
*/
|
|
27
|
+
export declare const PRONOUN_WORDS: ReadonlySet<string>;
|
|
28
|
+
/**
|
|
29
|
+
* The five case rows of a `define pronouns` block (ADR-242 D7, ruled Q-1)
|
|
30
|
+
* — exactly the cases the assembler's pronoun table keys. All five are
|
|
31
|
+
* required; order is free (named rows, not positional).
|
|
32
|
+
*/
|
|
33
|
+
export declare const PRONOUN_CASES: ReadonlyArray<string>;
|
|
20
34
|
/**
|
|
21
35
|
* State adjectives (ratchet D1): `is [not] <adj>` predicates read live from
|
|
22
36
|
* world trait state (OpenableTrait.isOpen, LockableTrait.isLocked,
|
|
@@ -33,11 +47,53 @@ export declare const PLATFORM_STATE_PAIRS: ReadonlyArray<{
|
|
|
33
47
|
pair: [string, string];
|
|
34
48
|
trait: string;
|
|
35
49
|
}>;
|
|
50
|
+
/**
|
|
51
|
+
* `starts <state>` initializer pairings (ADR-231 D5a, approved 2026-07-17):
|
|
52
|
+
* each accepted state word after `starts` on a composition line, mapped to
|
|
53
|
+
* the trait adjective that must be composed on the same entity — the
|
|
54
|
+
* analyzer's pairing gate (`analysis.starts-state-pairing`). The state
|
|
55
|
+
* adjective is an *initializer* of the trait's initial-value field, never
|
|
56
|
+
* stored story state (the shadow-state ratchet survives: `locked`, `open`,
|
|
57
|
+
* `on`, … stay derivable). Future stateful traits extend this table, not
|
|
58
|
+
* the code. Platform field mappings (`isLocked`, `isOpen`, `isOn`) live in
|
|
59
|
+
* @sharpee/story-loader, keeping this file names-only.
|
|
60
|
+
*/
|
|
61
|
+
export declare const STARTS_STATE_PAIRINGS: ReadonlyMap<string, string>;
|
|
36
62
|
/**
|
|
37
63
|
* Event verbs entity `on`/`after` clauses recognize beyond action gerunds
|
|
38
64
|
* (the curated event-selector map's language side; the if.event.* bindings
|
|
39
65
|
* are the loader's side of Interface Contract 2). Gerund register since
|
|
40
66
|
* the ownership package (ratchet D3): `after entering it`.
|
|
67
|
+
* `leaving` (ratchet R3, ADR-236 D6) exists only as a region crossing
|
|
68
|
+
* reaction — the loader refuses it on any other owner.
|
|
41
69
|
*/
|
|
42
70
|
export declare const EVENT_VERBS: ReadonlySet<string>;
|
|
71
|
+
/**
|
|
72
|
+
* Client capability flags (ADR-216 `client has <capability>` and channel
|
|
73
|
+
* `gated by` lines), in Chord spelling — hyphenated words mapping
|
|
74
|
+
* mechanically to the platform's camelCase `ClientCapabilities` boolean
|
|
75
|
+
* keys (`split-pane` → `splitPane`). `text` is excluded: it is always
|
|
76
|
+
* true and cannot gate. The loader-side conformance test pins this list
|
|
77
|
+
* against the platform's real flag set.
|
|
78
|
+
*/
|
|
79
|
+
export declare const CLIENT_CAPABILITY_FLAGS: ReadonlySet<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Curated aliases for the stdlib event chains a `define chain … from` hatch may
|
|
82
|
+
* replace (ADR-094). The kebab alias is the Chord-facing name; @sharpee/story-loader
|
|
83
|
+
* maps it to the dotted platform chain key + trigger (Interface Contract, like the
|
|
84
|
+
* message-alias ACL). Chord validates the NAME here (platform-free); an alias absent
|
|
85
|
+
* from this set is `analysis.unknown-chain`. One stdlib chain exists today.
|
|
86
|
+
*/
|
|
87
|
+
export declare const STDLIB_CHAIN_NAMES: ReadonlySet<string>;
|
|
88
|
+
/** Chord capability word → the platform's camelCase key (`split-pane` → `splitPane`). */
|
|
89
|
+
export declare function capabilityKeyOf(word: string): string;
|
|
90
|
+
/**
|
|
91
|
+
* ADR-255 Interface Contract 3 (names side): the closed set of curated kebab
|
|
92
|
+
* aliases valid in `override message <alias>` — one per standard-action message
|
|
93
|
+
* id in lang-en-us. Names only; the alias → `if.action.*` binding lives in
|
|
94
|
+
* `@sharpee/story-loader`. The data (and its generation rule) is in
|
|
95
|
+
* `message-alias-catalog.ts`; re-exported here so the analyzer reads the ACL
|
|
96
|
+
* vocabulary through the single catalog surface.
|
|
97
|
+
*/
|
|
98
|
+
export { MESSAGE_OVERRIDE_ALIASES } from './message-alias-catalog.js';
|
|
43
99
|
//# sourceMappingURL=catalog.d.ts.map
|
package/catalog.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../../repos/sharpee_v2/packages/chord/src/catalog.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../../repos/sharpee_v2/packages/chord/src/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,6EAA6E;AAC7E,eAAO,MAAM,UAAU,EAAE,WAAW,CAAC,MAAM,CAOzC,CAAC;AAEH,8CAA8C;AAC9C,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAqB/C,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,MAAM,CAAwC,CAAC;AAEvF;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,MAAM,CAA0E,CAAC;AAE3H;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAS/C,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAMzF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAO5D,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,EAAE,WAAW,CAAC,MAAM,CAAoC,CAAC;AAEjF;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAAW,CAAC,MAAM,CAgBtD,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAAgC,CAAC;AAEpF,yFAAyF;AACzF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;;;;GAOG;AACH,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC"}
|
package/catalog.js
CHANGED
|
@@ -9,13 +9,15 @@
|
|
|
9
9
|
* only so the compiler stays platform-free.
|
|
10
10
|
*
|
|
11
11
|
* Public interface: KIND_NOUNS, TRAIT_ADJECTIVES, STATE_ADJECTIVES,
|
|
12
|
-
* PLATFORM_STATE_PAIRS, EVENT_VERBS
|
|
12
|
+
* PLATFORM_STATE_PAIRS, STARTS_STATE_PAIRINGS, EVENT_VERBS,
|
|
13
|
+
* PRONOUN_WORDS, PRONOUN_CASES.
|
|
13
14
|
* Owner context: @sharpee/chord (language frontend; browser-safe).
|
|
14
15
|
* Growing any of these sets is a grammar change — owner approval via
|
|
15
16
|
* docs/architecture/chord-grammar-changes.md.
|
|
16
17
|
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.EVENT_VERBS = exports.PLATFORM_STATE_PAIRS = exports.STATE_ADJECTIVES = exports.TRAIT_ADJECTIVES = exports.KIND_NOUNS = void 0;
|
|
19
|
+
exports.MESSAGE_OVERRIDE_ALIASES = exports.STDLIB_CHAIN_NAMES = exports.CLIENT_CAPABILITY_FLAGS = exports.EVENT_VERBS = exports.STARTS_STATE_PAIRINGS = exports.PLATFORM_STATE_PAIRS = exports.STATE_ADJECTIVES = exports.PRONOUN_CASES = exports.PRONOUN_WORDS = exports.TRAIT_ADJECTIVES = exports.KIND_NOUNS = void 0;
|
|
20
|
+
exports.capabilityKeyOf = capabilityKeyOf;
|
|
19
21
|
/** v1 kind nouns (take an article: `a room`). Plain thing = no kind noun. */
|
|
20
22
|
exports.KIND_NOUNS = new Set([
|
|
21
23
|
'room',
|
|
@@ -23,6 +25,7 @@ exports.KIND_NOUNS = new Set([
|
|
|
23
25
|
'person',
|
|
24
26
|
'container',
|
|
25
27
|
'supporter',
|
|
28
|
+
'region', // ratchet R1 (ADR-236 D1, 2026-07-17) — named room group; membership via `containing`
|
|
26
29
|
]);
|
|
27
30
|
/** v1 trait adjectives (bare, no article). */
|
|
28
31
|
exports.TRAIT_ADJECTIVES = new Set([
|
|
@@ -38,7 +41,28 @@ exports.TRAIT_ADJECTIVES = new Set([
|
|
|
38
41
|
'light-source',
|
|
39
42
|
'plural',
|
|
40
43
|
'dark',
|
|
44
|
+
'enterable', // ADR-218 §1a (ratchet F1) — composes EnterableTrait; always explicit
|
|
45
|
+
'climbable', // ADR-218 §1a (ratchet F2) — composes ClimbableTrait
|
|
46
|
+
'cuttable', // ADR-230 D3c — composes CuttableTrait; `with tool <entity>` config; requires a cut implementation
|
|
47
|
+
'diggable', // ADR-230 Phase 6 — composes DiggableTrait; same tool config + implementation rule as cuttable
|
|
48
|
+
'drinkable', // ratchet G1 (2026-07-17) — composes EdibleTrait with liquid=true (drunk, not eaten)
|
|
49
|
+
'concealed', // ratchet G2 (2026-07-17) — marker: IdentityTrait.concealed = true; searching reveals
|
|
50
|
+
'hiding-spot', // ratchet G3 (2026-07-17) — composes ConcealmentTrait; bare = all positions, `with position <word>` narrows
|
|
51
|
+
'proper', // ratchet H1 (ADR-242 D1, 2026-07-19) — person-only, unconditional: IdentityTrait.properName (bare name, no article)
|
|
41
52
|
]);
|
|
53
|
+
/**
|
|
54
|
+
* Standard pronoun sets (ADR-242 D5) — the four rows the lang-{locale}
|
|
55
|
+
* assembler ships. A `pronouns <word>` person line accepts these or a
|
|
56
|
+
* story-defined named set (`define pronouns <name>`); defining a set that
|
|
57
|
+
* shadows one of these is an error.
|
|
58
|
+
*/
|
|
59
|
+
exports.PRONOUN_WORDS = new Set(['he', 'she', 'it', 'they']);
|
|
60
|
+
/**
|
|
61
|
+
* The five case rows of a `define pronouns` block (ADR-242 D7, ruled Q-1)
|
|
62
|
+
* — exactly the cases the assembler's pronoun table keys. All five are
|
|
63
|
+
* required; order is free (named rows, not positional).
|
|
64
|
+
*/
|
|
65
|
+
exports.PRONOUN_CASES = ['subject', 'object', 'possessive', 'possessive-pronoun', 'reflexive'];
|
|
42
66
|
/**
|
|
43
67
|
* State adjectives (ratchet D1): `is [not] <adj>` predicates read live from
|
|
44
68
|
* world trait state (OpenableTrait.isOpen, LockableTrait.isLocked,
|
|
@@ -67,11 +91,79 @@ exports.PLATFORM_STATE_PAIRS = [
|
|
|
67
91
|
{ pair: ['lit', 'unlit'], trait: 'light-source' },
|
|
68
92
|
{ pair: ['worn', 'unworn'], trait: 'wearable' },
|
|
69
93
|
];
|
|
94
|
+
/**
|
|
95
|
+
* `starts <state>` initializer pairings (ADR-231 D5a, approved 2026-07-17):
|
|
96
|
+
* each accepted state word after `starts` on a composition line, mapped to
|
|
97
|
+
* the trait adjective that must be composed on the same entity — the
|
|
98
|
+
* analyzer's pairing gate (`analysis.starts-state-pairing`). The state
|
|
99
|
+
* adjective is an *initializer* of the trait's initial-value field, never
|
|
100
|
+
* stored story state (the shadow-state ratchet survives: `locked`, `open`,
|
|
101
|
+
* `on`, … stay derivable). Future stateful traits extend this table, not
|
|
102
|
+
* the code. Platform field mappings (`isLocked`, `isOpen`, `isOn`) live in
|
|
103
|
+
* @sharpee/story-loader, keeping this file names-only.
|
|
104
|
+
*/
|
|
105
|
+
exports.STARTS_STATE_PAIRINGS = new Map([
|
|
106
|
+
['locked', 'lockable'],
|
|
107
|
+
['unlocked', 'lockable'],
|
|
108
|
+
['closed', 'openable'],
|
|
109
|
+
['open', 'openable'],
|
|
110
|
+
['off', 'switchable'],
|
|
111
|
+
['on', 'switchable'],
|
|
112
|
+
]);
|
|
70
113
|
/**
|
|
71
114
|
* Event verbs entity `on`/`after` clauses recognize beyond action gerunds
|
|
72
115
|
* (the curated event-selector map's language side; the if.event.* bindings
|
|
73
116
|
* are the loader's side of Interface Contract 2). Gerund register since
|
|
74
117
|
* the ownership package (ratchet D3): `after entering it`.
|
|
118
|
+
* `leaving` (ratchet R3, ADR-236 D6) exists only as a region crossing
|
|
119
|
+
* reaction — the loader refuses it on any other owner.
|
|
120
|
+
*/
|
|
121
|
+
exports.EVENT_VERBS = new Set(['entering', 'leaving']);
|
|
122
|
+
/**
|
|
123
|
+
* Client capability flags (ADR-216 `client has <capability>` and channel
|
|
124
|
+
* `gated by` lines), in Chord spelling — hyphenated words mapping
|
|
125
|
+
* mechanically to the platform's camelCase `ClientCapabilities` boolean
|
|
126
|
+
* keys (`split-pane` → `splitPane`). `text` is excluded: it is always
|
|
127
|
+
* true and cannot gate. The loader-side conformance test pins this list
|
|
128
|
+
* against the platform's real flag set.
|
|
129
|
+
*/
|
|
130
|
+
exports.CLIENT_CAPABILITY_FLAGS = new Set([
|
|
131
|
+
'images',
|
|
132
|
+
'animations',
|
|
133
|
+
'video',
|
|
134
|
+
'sound',
|
|
135
|
+
'music',
|
|
136
|
+
'speech',
|
|
137
|
+
'split-pane',
|
|
138
|
+
'status-bar',
|
|
139
|
+
'sidebar',
|
|
140
|
+
'clickable-text',
|
|
141
|
+
'clickable-image',
|
|
142
|
+
'drag-drop',
|
|
143
|
+
'transitions',
|
|
144
|
+
'layers',
|
|
145
|
+
'custom-fonts',
|
|
146
|
+
]);
|
|
147
|
+
/**
|
|
148
|
+
* Curated aliases for the stdlib event chains a `define chain … from` hatch may
|
|
149
|
+
* replace (ADR-094). The kebab alias is the Chord-facing name; @sharpee/story-loader
|
|
150
|
+
* maps it to the dotted platform chain key + trigger (Interface Contract, like the
|
|
151
|
+
* message-alias ACL). Chord validates the NAME here (platform-free); an alias absent
|
|
152
|
+
* from this set is `analysis.unknown-chain`. One stdlib chain exists today.
|
|
153
|
+
*/
|
|
154
|
+
exports.STDLIB_CHAIN_NAMES = new Set(['opened-revealed']);
|
|
155
|
+
/** Chord capability word → the platform's camelCase key (`split-pane` → `splitPane`). */
|
|
156
|
+
function capabilityKeyOf(word) {
|
|
157
|
+
return word.replace(/-([a-z])/g, (_, ch) => ch.toUpperCase());
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* ADR-255 Interface Contract 3 (names side): the closed set of curated kebab
|
|
161
|
+
* aliases valid in `override message <alias>` — one per standard-action message
|
|
162
|
+
* id in lang-en-us. Names only; the alias → `if.action.*` binding lives in
|
|
163
|
+
* `@sharpee/story-loader`. The data (and its generation rule) is in
|
|
164
|
+
* `message-alias-catalog.ts`; re-exported here so the analyzer reads the ACL
|
|
165
|
+
* vocabulary through the single catalog surface.
|
|
75
166
|
*/
|
|
76
|
-
|
|
167
|
+
var message_alias_catalog_js_1 = require("./message-alias-catalog.js");
|
|
168
|
+
Object.defineProperty(exports, "MESSAGE_OVERRIDE_ALIASES", { enumerable: true, get: function () { return message_alias_catalog_js_1.MESSAGE_OVERRIDE_ALIASES; } });
|
|
77
169
|
//# sourceMappingURL=catalog.js.map
|
package/catalog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../../repos/sharpee_v2/packages/chord/src/catalog.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../../repos/sharpee_v2/packages/chord/src/catalog.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAmJH,0CAEC;AAnJD,6EAA6E;AAChE,QAAA,UAAU,GAAwB,IAAI,GAAG,CAAC;IACrD,MAAM;IACN,MAAM;IACN,QAAQ;IACR,WAAW;IACX,WAAW;IACX,QAAQ,EAAE,sFAAsF;CACjG,CAAC,CAAC;AAEH,8CAA8C;AACjC,QAAA,gBAAgB,GAAwB,IAAI,GAAG,CAAC;IAC3D,SAAS;IACT,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,YAAY;IACZ,QAAQ;IACR,UAAU;IACV,UAAU;IACV,cAAc;IACd,QAAQ;IACR,MAAM;IACN,WAAW,EAAE,sEAAsE;IACnF,WAAW,EAAE,qDAAqD;IAClE,UAAU,EAAE,mGAAmG;IAC/G,UAAU,EAAE,+FAA+F;IAC3G,WAAW,EAAE,qFAAqF;IAClG,WAAW,EAAE,sFAAsF;IACnG,aAAa,EAAE,4GAA4G;IAC3H,QAAQ,EAAE,qHAAqH;CAChI,CAAC,CAAC;AAEH;;;;;GAKG;AACU,QAAA,aAAa,GAAwB,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAEvF;;;;GAIG;AACU,QAAA,aAAa,GAA0B,CAAC,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAAC;AAE3H;;;;;GAKG;AACU,QAAA,gBAAgB,GA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IACX,aAAa;IACb,QAAQ;IACR,cAAc;CACf,CAAC,CAAC;AAEH;;;;;;GAMG;AACU,QAAA,kBAAkB,GAAwB,IAAI,GAAG,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAEpF,yFAAyF;AACzF,SAAgB,eAAe,CAAC,IAAY;IAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAU,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;;GAOG;AACH,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA"}
|
package/diagnostics.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Public interface: Diagnostic, DiagnosticSeverity, DiagnosticBag.
|
|
9
9
|
* Owner context: @sharpee/chord (language frontend; browser-safe).
|
|
10
10
|
*/
|
|
11
|
-
import type { Span } from './span';
|
|
11
|
+
import type { Span } from './span.js';
|
|
12
12
|
export type DiagnosticSeverity = 'error' | 'warning';
|
|
13
13
|
/** One reported problem, anchored to source. */
|
|
14
14
|
export interface Diagnostic {
|
package/diagnostics.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../../repos/sharpee_v2/packages/chord/src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../../repos/sharpee_v2/packages/chord/src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,SAAS,CAAC;AAErD,gDAAgD;AAChD,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,IAAI,CAAC;CACZ;AAED;;;;GAIG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAAoB;IAEjC,kCAAkC;IAClC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI;IAItD,mCAAmC;IACnC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI;IAIxD,uCAAuC;IACvC,GAAG,IAAI,SAAS,UAAU,EAAE;IAI5B,0DAA0D;IAC1D,SAAS,IAAI,OAAO;CAGrB"}
|
package/index.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import type { StoryFile } from './ast';
|
|
2
|
-
import { Diagnostic } from './diagnostics';
|
|
3
|
-
import type { StoryIR } from './ir';
|
|
4
|
-
export * from './ast';
|
|
5
|
-
export * from './ir';
|
|
6
|
-
export { analyze } from './analyzer';
|
|
7
|
-
export { KIND_NOUNS, TRAIT_ADJECTIVES, STATE_ADJECTIVES, PLATFORM_STATE_PAIRS, EVENT_VERBS } from './catalog';
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
1
|
+
import type { StoryFile } from './ast.js';
|
|
2
|
+
import { Diagnostic } from './diagnostics.js';
|
|
3
|
+
import type { StoryIR } from './ir.js';
|
|
4
|
+
export * from './ast.js';
|
|
5
|
+
export * from './ir.js';
|
|
6
|
+
export { analyze, normalizeTopic } from './analyzer.js';
|
|
7
|
+
export { KIND_NOUNS, TRAIT_ADJECTIVES, STATE_ADJECTIVES, PLATFORM_STATE_PAIRS, STARTS_STATE_PAIRINGS, EVENT_VERBS, CLIENT_CAPABILITY_FLAGS, capabilityKeyOf, PRONOUN_WORDS, PRONOUN_CASES, MESSAGE_OVERRIDE_ALIASES, STDLIB_CHAIN_NAMES } from './catalog.js';
|
|
8
|
+
export { EXTENSION_MANIFESTS, COMBAT_MANIFEST, NPC_MANIFEST, manifestForAdjective } from './manifests/index.js';
|
|
9
|
+
export type { ExtensionManifest, ManifestAdjective, ManifestField } from './manifests/index.js';
|
|
10
|
+
export { PHRASEBOOK_REGISTRY } from './phrasebooks.js';
|
|
11
|
+
export type { PhrasebookManifest } from './phrasebooks.js';
|
|
12
|
+
export { Diagnostic, DiagnosticSeverity, DiagnosticBag } from './diagnostics.js';
|
|
13
|
+
export { Span, spanOf, mergeSpans } from './span.js';
|
|
14
|
+
export { lex, Line, Token, TokenKind } from './lexer.js';
|
|
15
|
+
export { parseStory } from './parser.js';
|
|
12
16
|
/** Result of parsing one `.story` source. */
|
|
13
17
|
export interface ParseResult {
|
|
14
18
|
ast: StoryFile;
|
|
@@ -30,10 +34,24 @@ export interface CompileResult {
|
|
|
30
34
|
diagnostics: readonly Diagnostic[];
|
|
31
35
|
ok: boolean;
|
|
32
36
|
}
|
|
37
|
+
/** Host hooks for compile() (ADR-251, generalizing ADR-250 D2). */
|
|
38
|
+
export interface CompileOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Resolves an `import "<file>"` target to the fragment's source text, or
|
|
41
|
+
* null when unresolvable. The compiler appends `.chord` before calling
|
|
42
|
+
* this, so `path` always arrives as `"<name>.chord"` (e.g.
|
|
43
|
+
* `"regions/harbor.chord"`) — the resolver just maps that name to text.
|
|
44
|
+
* The HOST owns the base directory (relative to the importing story
|
|
45
|
+
* file). The chord package stays filesystem-free: devkit/repokit supply
|
|
46
|
+
* an fs-backed resolver, the browser client a bundle-map resolver.
|
|
47
|
+
*/
|
|
48
|
+
importResolver?: (path: string) => string | null;
|
|
49
|
+
}
|
|
33
50
|
/**
|
|
34
|
-
* Compile `.story` source text: parse + analyze + build IR.
|
|
51
|
+
* Compile `.story` source text: parse + resolve imports + analyze + build IR.
|
|
35
52
|
* @param source full text of a `.story` file
|
|
53
|
+
* @param options host hooks (importResolver for `import "<file>"`)
|
|
36
54
|
* @returns AST, IR, and all diagnostics; `ok` gates use of the IR
|
|
37
55
|
*/
|
|
38
|
-
export declare function compile(source: string): CompileResult;
|
|
56
|
+
export declare function compile(source: string, options?: CompileOptions): CompileResult;
|
|
39
57
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../repos/sharpee_v2/packages/chord/src/index.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../repos/sharpee_v2/packages/chord/src/index.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAe,SAAS,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,UAAU,EAAiB,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGvC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,WAAW,EAAE,uBAAuB,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC9P,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAChH,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,6CAA6C;AAC7C,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,SAAS,CAAC;IACf,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IACnC,2DAA2D;IAC3D,EAAE,EAAE,OAAO,CAAC;CACb;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAIjD;AAED,qDAAqD;AACrD,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,SAAS,CAAC;IACf,uEAAuE;IACvE,EAAE,EAAE,OAAO,CAAC;IACZ,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IACnC,EAAE,EAAE,OAAO,CAAC;CACb;AAED,mEAAmE;AACnE,MAAM,WAAW,cAAc;IAC7B;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CAClD;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,aAAa,CAM/E"}
|
package/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.parseStory = exports.lex = exports.mergeSpans = exports.spanOf = exports.DiagnosticBag = exports.EVENT_VERBS = exports.PLATFORM_STATE_PAIRS = exports.STATE_ADJECTIVES = exports.TRAIT_ADJECTIVES = exports.KIND_NOUNS = exports.analyze = void 0;
|
|
17
|
+
exports.parseStory = exports.lex = exports.mergeSpans = exports.spanOf = exports.DiagnosticBag = exports.PHRASEBOOK_REGISTRY = exports.manifestForAdjective = exports.NPC_MANIFEST = exports.COMBAT_MANIFEST = exports.EXTENSION_MANIFESTS = exports.STDLIB_CHAIN_NAMES = exports.MESSAGE_OVERRIDE_ALIASES = exports.PRONOUN_CASES = exports.PRONOUN_WORDS = exports.capabilityKeyOf = exports.CLIENT_CAPABILITY_FLAGS = exports.EVENT_VERBS = exports.STARTS_STATE_PAIRINGS = exports.PLATFORM_STATE_PAIRS = exports.STATE_ADJECTIVES = exports.TRAIT_ADJECTIVES = exports.KIND_NOUNS = exports.normalizeTopic = exports.analyze = void 0;
|
|
18
18
|
exports.parse = parse;
|
|
19
19
|
exports.compile = compile;
|
|
20
20
|
/**
|
|
@@ -31,47 +31,127 @@ exports.compile = compile;
|
|
|
31
31
|
* never depend on platform-runtime packages (`if-domain` types at most);
|
|
32
32
|
* the runtime platform never depends on it (ADR-210 Direction rule).
|
|
33
33
|
*/
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
__exportStar(require("./ast"), exports);
|
|
38
|
-
__exportStar(require("./ir"), exports);
|
|
39
|
-
var
|
|
40
|
-
Object.defineProperty(exports, "analyze", { enumerable: true, get: function () { return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
Object.defineProperty(exports, "
|
|
44
|
-
Object.defineProperty(exports, "
|
|
45
|
-
Object.defineProperty(exports, "
|
|
46
|
-
Object.defineProperty(exports, "
|
|
47
|
-
|
|
48
|
-
Object.defineProperty(exports, "
|
|
49
|
-
|
|
50
|
-
Object.defineProperty(exports, "
|
|
51
|
-
Object.defineProperty(exports, "
|
|
52
|
-
|
|
53
|
-
Object.defineProperty(exports, "
|
|
54
|
-
|
|
55
|
-
|
|
34
|
+
const analyzer_js_1 = require("./analyzer.js");
|
|
35
|
+
const diagnostics_js_1 = require("./diagnostics.js");
|
|
36
|
+
const parser_js_1 = require("./parser.js");
|
|
37
|
+
__exportStar(require("./ast.js"), exports);
|
|
38
|
+
__exportStar(require("./ir.js"), exports);
|
|
39
|
+
var analyzer_js_2 = require("./analyzer.js");
|
|
40
|
+
Object.defineProperty(exports, "analyze", { enumerable: true, get: function () { return analyzer_js_2.analyze; } });
|
|
41
|
+
Object.defineProperty(exports, "normalizeTopic", { enumerable: true, get: function () { return analyzer_js_2.normalizeTopic; } });
|
|
42
|
+
var catalog_js_1 = require("./catalog.js");
|
|
43
|
+
Object.defineProperty(exports, "KIND_NOUNS", { enumerable: true, get: function () { return catalog_js_1.KIND_NOUNS; } });
|
|
44
|
+
Object.defineProperty(exports, "TRAIT_ADJECTIVES", { enumerable: true, get: function () { return catalog_js_1.TRAIT_ADJECTIVES; } });
|
|
45
|
+
Object.defineProperty(exports, "STATE_ADJECTIVES", { enumerable: true, get: function () { return catalog_js_1.STATE_ADJECTIVES; } });
|
|
46
|
+
Object.defineProperty(exports, "PLATFORM_STATE_PAIRS", { enumerable: true, get: function () { return catalog_js_1.PLATFORM_STATE_PAIRS; } });
|
|
47
|
+
Object.defineProperty(exports, "STARTS_STATE_PAIRINGS", { enumerable: true, get: function () { return catalog_js_1.STARTS_STATE_PAIRINGS; } });
|
|
48
|
+
Object.defineProperty(exports, "EVENT_VERBS", { enumerable: true, get: function () { return catalog_js_1.EVENT_VERBS; } });
|
|
49
|
+
Object.defineProperty(exports, "CLIENT_CAPABILITY_FLAGS", { enumerable: true, get: function () { return catalog_js_1.CLIENT_CAPABILITY_FLAGS; } });
|
|
50
|
+
Object.defineProperty(exports, "capabilityKeyOf", { enumerable: true, get: function () { return catalog_js_1.capabilityKeyOf; } });
|
|
51
|
+
Object.defineProperty(exports, "PRONOUN_WORDS", { enumerable: true, get: function () { return catalog_js_1.PRONOUN_WORDS; } });
|
|
52
|
+
Object.defineProperty(exports, "PRONOUN_CASES", { enumerable: true, get: function () { return catalog_js_1.PRONOUN_CASES; } });
|
|
53
|
+
Object.defineProperty(exports, "MESSAGE_OVERRIDE_ALIASES", { enumerable: true, get: function () { return catalog_js_1.MESSAGE_OVERRIDE_ALIASES; } });
|
|
54
|
+
Object.defineProperty(exports, "STDLIB_CHAIN_NAMES", { enumerable: true, get: function () { return catalog_js_1.STDLIB_CHAIN_NAMES; } });
|
|
55
|
+
var index_js_1 = require("./manifests/index.js");
|
|
56
|
+
Object.defineProperty(exports, "EXTENSION_MANIFESTS", { enumerable: true, get: function () { return index_js_1.EXTENSION_MANIFESTS; } });
|
|
57
|
+
Object.defineProperty(exports, "COMBAT_MANIFEST", { enumerable: true, get: function () { return index_js_1.COMBAT_MANIFEST; } });
|
|
58
|
+
Object.defineProperty(exports, "NPC_MANIFEST", { enumerable: true, get: function () { return index_js_1.NPC_MANIFEST; } });
|
|
59
|
+
Object.defineProperty(exports, "manifestForAdjective", { enumerable: true, get: function () { return index_js_1.manifestForAdjective; } });
|
|
60
|
+
var phrasebooks_js_1 = require("./phrasebooks.js");
|
|
61
|
+
Object.defineProperty(exports, "PHRASEBOOK_REGISTRY", { enumerable: true, get: function () { return phrasebooks_js_1.PHRASEBOOK_REGISTRY; } });
|
|
62
|
+
var diagnostics_js_2 = require("./diagnostics.js");
|
|
63
|
+
Object.defineProperty(exports, "DiagnosticBag", { enumerable: true, get: function () { return diagnostics_js_2.DiagnosticBag; } });
|
|
64
|
+
var span_js_1 = require("./span.js");
|
|
65
|
+
Object.defineProperty(exports, "spanOf", { enumerable: true, get: function () { return span_js_1.spanOf; } });
|
|
66
|
+
Object.defineProperty(exports, "mergeSpans", { enumerable: true, get: function () { return span_js_1.mergeSpans; } });
|
|
67
|
+
var lexer_js_1 = require("./lexer.js");
|
|
68
|
+
Object.defineProperty(exports, "lex", { enumerable: true, get: function () { return lexer_js_1.lex; } });
|
|
69
|
+
var parser_js_2 = require("./parser.js");
|
|
70
|
+
Object.defineProperty(exports, "parseStory", { enumerable: true, get: function () { return parser_js_2.parseStory; } });
|
|
56
71
|
/**
|
|
57
72
|
* Parse `.story` source text.
|
|
58
73
|
* @param source full text of a `.story` file
|
|
59
74
|
* @returns the AST (possibly partial on errors) plus all diagnostics
|
|
60
75
|
*/
|
|
61
76
|
function parse(source) {
|
|
62
|
-
const bag = new
|
|
63
|
-
const ast = (0,
|
|
77
|
+
const bag = new diagnostics_js_1.DiagnosticBag();
|
|
78
|
+
const ast = (0, parser_js_1.parseStory)(source, bag);
|
|
64
79
|
return { ast, diagnostics: bag.all(), ok: !bag.hasErrors() };
|
|
65
80
|
}
|
|
66
81
|
/**
|
|
67
|
-
* Compile `.story` source text: parse + analyze + build IR.
|
|
82
|
+
* Compile `.story` source text: parse + resolve imports + analyze + build IR.
|
|
68
83
|
* @param source full text of a `.story` file
|
|
84
|
+
* @param options host hooks (importResolver for `import "<file>"`)
|
|
69
85
|
* @returns AST, IR, and all diagnostics; `ok` gates use of the IR
|
|
70
86
|
*/
|
|
71
|
-
function compile(source) {
|
|
72
|
-
const bag = new
|
|
73
|
-
const ast = (0,
|
|
74
|
-
|
|
87
|
+
function compile(source, options) {
|
|
88
|
+
const bag = new diagnostics_js_1.DiagnosticBag();
|
|
89
|
+
const ast = (0, parser_js_1.parseStory)(source, bag);
|
|
90
|
+
resolveImports(ast, options, bag);
|
|
91
|
+
const ir = (0, analyzer_js_1.analyze)(ast, bag);
|
|
75
92
|
return { ast, ir, diagnostics: bag.all(), ok: !bag.hasErrors() };
|
|
76
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Splice each `import "<file>"` declaration with the imported fragment's
|
|
96
|
+
* complete declarations, in place (import site = arbitration position —
|
|
97
|
+
* ADR-251 D4: "an import is a paste"). The compiler appends `.chord` to
|
|
98
|
+
* the target before resolving (D2), so the host `importResolver` always
|
|
99
|
+
* receives `"<name>.chord"`. A fragment may contain any complete
|
|
100
|
+
* declaration EXCEPT a `story` header (D3 → `analysis.import-fragment-story`)
|
|
101
|
+
* or a nested `import` (D5: imports are flat → `analysis.import-fragment-nested`);
|
|
102
|
+
* a fragment that fails to parse cleanly (partial/non-declaration content)
|
|
103
|
+
* additionally raises `analysis.import-fragment-content` at the import site,
|
|
104
|
+
* beside the granular fragment parse errors. Processed imports are removed
|
|
105
|
+
* from the AST either way, so the analyzer never double-reports. Fragment
|
|
106
|
+
* diagnostics are re-reported with the fragment name prefixed, since spans
|
|
107
|
+
* are file-relative.
|
|
108
|
+
*/
|
|
109
|
+
function resolveImports(ast, options, bag) {
|
|
110
|
+
if (!ast.declarations.some((d) => d.kind === 'import'))
|
|
111
|
+
return;
|
|
112
|
+
const resolved = [];
|
|
113
|
+
for (const decl of ast.declarations) {
|
|
114
|
+
if (decl.kind !== 'import') {
|
|
115
|
+
resolved.push(decl);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
// D2: the extension is a language fact, appended here — the resolver stays dumb.
|
|
119
|
+
const fragmentName = `${decl.path}.chord`;
|
|
120
|
+
const text = options?.importResolver ? options.importResolver(fragmentName) : null;
|
|
121
|
+
if (text === null || text === undefined) {
|
|
122
|
+
bag.error('analysis.import-unresolved', options?.importResolver
|
|
123
|
+
? `Cannot resolve \`import "${decl.path}"\` — \`${fragmentName}\` was not found.`
|
|
124
|
+
: `\`import "${decl.path}"\` needs an import resolver — this compile host provides none.`, decl.span);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const fragBag = new diagnostics_js_1.DiagnosticBag();
|
|
128
|
+
const fragAst = (0, parser_js_1.parseStory)(text, fragBag);
|
|
129
|
+
for (const d of fragBag.all()) {
|
|
130
|
+
// Fragment spans are relative to the fragment file — prefix the name.
|
|
131
|
+
bag[d.severity === 'error' ? 'error' : 'warning'](d.code, `[${fragmentName}] ${d.message}`, d.span);
|
|
132
|
+
}
|
|
133
|
+
// D6 span contract: fragment diagnostics carry the fragment's OWN span
|
|
134
|
+
// (with the `[<name>.chord]` prefix identifying the file); only the
|
|
135
|
+
// unresolved-import diagnostic above points at the main-file import line.
|
|
136
|
+
if (fragBag.hasErrors()) {
|
|
137
|
+
// Partial / non-declaration content — the granular parse errors above
|
|
138
|
+
// carry the detail; anchor the category diagnostic at the first of them.
|
|
139
|
+
const firstError = fragBag.all().find((d) => d.severity === 'error');
|
|
140
|
+
bag.error('analysis.import-fragment-content', `[${fragmentName}] This import's fragment did not parse into complete declarations.`, firstError ? firstError.span : decl.span);
|
|
141
|
+
}
|
|
142
|
+
if (fragAst.header) {
|
|
143
|
+
bag.error('analysis.import-fragment-story', `[${fragmentName}] An imported fragment carries no story header — the \`story\` block lives only in the main \`.story\` file.`, fragAst.header.span);
|
|
144
|
+
}
|
|
145
|
+
for (const d of fragAst.declarations) {
|
|
146
|
+
if (d.kind === 'import') {
|
|
147
|
+
// D5: imports do not nest — only the main `.story` file may import.
|
|
148
|
+
bag.error('analysis.import-fragment-nested', `[${fragmentName}] Imports do not nest — remove the \`import "${d.path}"\` line from \`${fragmentName}\`.`, d.span);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
resolved.push(d);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
ast.declarations = resolved;
|
|
156
|
+
}
|
|
77
157
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../repos/sharpee_v2/packages/chord/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../repos/sharpee_v2/packages/chord/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA8CA,sBAIC;AA+BD,0BAMC;AAvFD;;;;;;;;;;;;;GAaG;AACH,+CAAwC;AAExC,qDAA6D;AAE7D,2CAAyC;AAEzC,2CAAyB;AACzB,0CAAwB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