@sharpee/if-domain 0.9.60-beta
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/README.md +71 -0
- package/dist/changes.d.ts +8 -0
- package/dist/changes.d.ts.map +1 -0
- package/dist/changes.js +6 -0
- package/dist/changes.js.map +1 -0
- package/dist/contracts.d.ts +270 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +6 -0
- package/dist/contracts.js.map +1 -0
- package/dist/events.d.ts +124 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +123 -0
- package/dist/events.js.map +1 -0
- package/dist/grammar/grammar-builder.d.ts +507 -0
- package/dist/grammar/grammar-builder.d.ts.map +1 -0
- package/dist/grammar/grammar-builder.js +47 -0
- package/dist/grammar/grammar-builder.js.map +1 -0
- package/dist/grammar/grammar-engine.d.ts +65 -0
- package/dist/grammar/grammar-engine.d.ts.map +1 -0
- package/dist/grammar/grammar-engine.js +370 -0
- package/dist/grammar/grammar-engine.js.map +1 -0
- package/dist/grammar/index.d.ts +10 -0
- package/dist/grammar/index.d.ts.map +1 -0
- package/dist/grammar/index.js +26 -0
- package/dist/grammar/index.js.map +1 -0
- package/dist/grammar/pattern-compiler.d.ts +38 -0
- package/dist/grammar/pattern-compiler.d.ts.map +1 -0
- package/dist/grammar/pattern-compiler.js +22 -0
- package/dist/grammar/pattern-compiler.js.map +1 -0
- package/dist/grammar/scope-builder.d.ts +26 -0
- package/dist/grammar/scope-builder.d.ts.map +1 -0
- package/dist/grammar/scope-builder.js +67 -0
- package/dist/grammar/scope-builder.js.map +1 -0
- package/dist/grammar/vocabulary-provider.d.ts +163 -0
- package/dist/grammar/vocabulary-provider.d.ts.map +1 -0
- package/dist/grammar/vocabulary-provider.js +89 -0
- package/dist/grammar/vocabulary-provider.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/language-provider.d.ts +106 -0
- package/dist/language-provider.d.ts.map +1 -0
- package/dist/language-provider.js +14 -0
- package/dist/language-provider.js.map +1 -0
- package/dist/parser-contracts/index.d.ts +10 -0
- package/dist/parser-contracts/index.d.ts.map +1 -0
- package/dist/parser-contracts/index.js +26 -0
- package/dist/parser-contracts/index.js.map +1 -0
- package/dist/parser-contracts/parser-factory.d.ts +46 -0
- package/dist/parser-contracts/parser-factory.d.ts.map +1 -0
- package/dist/parser-contracts/parser-factory.js +78 -0
- package/dist/parser-contracts/parser-factory.js.map +1 -0
- package/dist/parser-contracts/parser-internals.d.ts +125 -0
- package/dist/parser-contracts/parser-internals.d.ts.map +1 -0
- package/dist/parser-contracts/parser-internals.js +26 -0
- package/dist/parser-contracts/parser-internals.js.map +1 -0
- package/dist/parser-contracts/parser-types.d.ts +128 -0
- package/dist/parser-contracts/parser-types.d.ts.map +1 -0
- package/dist/parser-contracts/parser-types.js +9 -0
- package/dist/parser-contracts/parser-types.js.map +1 -0
- package/dist/parser-language-provider.d.ts +158 -0
- package/dist/parser-language-provider.d.ts.map +1 -0
- package/dist/parser-language-provider.js +10 -0
- package/dist/parser-language-provider.js.map +1 -0
- package/dist/sequencing.d.ts +53 -0
- package/dist/sequencing.d.ts.map +1 -0
- package/dist/sequencing.js +6 -0
- package/dist/sequencing.js.map +1 -0
- package/dist/vocabulary-contracts/index.d.ts +7 -0
- package/dist/vocabulary-contracts/index.d.ts.map +1 -0
- package/dist/vocabulary-contracts/index.js +23 -0
- package/dist/vocabulary-contracts/index.js.map +1 -0
- package/dist/vocabulary-contracts/vocabulary-adapters.d.ts +19 -0
- package/dist/vocabulary-contracts/vocabulary-adapters.d.ts.map +1 -0
- package/dist/vocabulary-contracts/vocabulary-adapters.js +73 -0
- package/dist/vocabulary-contracts/vocabulary-adapters.js.map +1 -0
- package/dist/vocabulary-contracts/vocabulary-registry.d.ts +98 -0
- package/dist/vocabulary-contracts/vocabulary-registry.d.ts.map +1 -0
- package/dist/vocabulary-contracts/vocabulary-registry.js +383 -0
- package/dist/vocabulary-contracts/vocabulary-registry.js.map +1 -0
- package/dist/vocabulary-contracts/vocabulary-types.d.ts +240 -0
- package/dist/vocabulary-contracts/vocabulary-types.d.ts.map +1 -0
- package/dist/vocabulary-contracts/vocabulary-types.js +64 -0
- package/dist/vocabulary-contracts/vocabulary-types.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Grammar Vocabulary Provider
|
|
3
|
+
* @description Context-aware vocabulary system for grammar pattern matching (ADR-082)
|
|
4
|
+
*
|
|
5
|
+
* This is distinct from vocabulary-contracts/VocabularyProvider which is for
|
|
6
|
+
* providing vocabulary entries to VocabularyRegistry. This system is specifically
|
|
7
|
+
* for context-aware vocabulary categories used in grammar slot matching.
|
|
8
|
+
*
|
|
9
|
+
* Vocabulary categories are registered with optional context predicates.
|
|
10
|
+
* The parser only considers a pattern if its vocabulary is active in the current context.
|
|
11
|
+
*/
|
|
12
|
+
import { GrammarContext } from './grammar-builder';
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for a vocabulary category
|
|
15
|
+
*/
|
|
16
|
+
export interface GrammarVocabularyConfig {
|
|
17
|
+
/** Words in this vocabulary category */
|
|
18
|
+
words: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Optional context predicate - if provided, vocabulary is only active
|
|
21
|
+
* when this function returns true for the current GrammarContext.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* vocab.define('panel-colors', {
|
|
26
|
+
* words: ['red', 'yellow', 'mahogany', 'pine'],
|
|
27
|
+
* when: (ctx) => ctx.currentLocation === insideMirrorId
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
when?: (ctx: GrammarContext) => boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Result of a grammar vocabulary match
|
|
35
|
+
*/
|
|
36
|
+
export interface GrammarVocabularyMatch {
|
|
37
|
+
/** The matched word (normalized to lowercase) */
|
|
38
|
+
word: string;
|
|
39
|
+
/** The category this word was matched from */
|
|
40
|
+
category: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Context-aware vocabulary provider for grammar pattern matching.
|
|
44
|
+
*
|
|
45
|
+
* Stories register vocabulary categories with optional context predicates.
|
|
46
|
+
* The parser checks if a category is active before attempting to match words.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Story initialization
|
|
51
|
+
* const vocab = world.getGrammarVocabularyProvider();
|
|
52
|
+
*
|
|
53
|
+
* // Global vocabulary (always active)
|
|
54
|
+
* vocab.define('manner', {
|
|
55
|
+
* words: ['carefully', 'quickly', 'forcefully']
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* // Context-specific vocabulary
|
|
59
|
+
* vocab.define('panel-colors', {
|
|
60
|
+
* words: ['red', 'yellow', 'mahogany', 'pine'],
|
|
61
|
+
* when: (ctx) => ctx.currentLocation === insideMirrorId
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* // Grammar pattern references the category
|
|
65
|
+
* grammar
|
|
66
|
+
* .define('push :color panel')
|
|
67
|
+
* .fromVocabulary('color', 'panel-colors')
|
|
68
|
+
* .mapsTo('push_panel')
|
|
69
|
+
* .build();
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export interface IGrammarVocabularyProvider {
|
|
73
|
+
/**
|
|
74
|
+
* Define a named vocabulary category.
|
|
75
|
+
*
|
|
76
|
+
* @param category - Unique category name (e.g., 'panel-colors', 'dial-positions')
|
|
77
|
+
* @param config - Words and optional context predicate
|
|
78
|
+
* @throws Error if category already exists (use extend() to add words)
|
|
79
|
+
*/
|
|
80
|
+
define(category: string, config: GrammarVocabularyConfig): void;
|
|
81
|
+
/**
|
|
82
|
+
* Extend an existing category with additional words.
|
|
83
|
+
* The context predicate is inherited from the original definition.
|
|
84
|
+
*
|
|
85
|
+
* @param category - Existing category name
|
|
86
|
+
* @param words - Additional words to add
|
|
87
|
+
* @throws Error if category doesn't exist
|
|
88
|
+
*/
|
|
89
|
+
extend(category: string, words: string[]): void;
|
|
90
|
+
/**
|
|
91
|
+
* Check if a word matches a category in the current context.
|
|
92
|
+
*
|
|
93
|
+
* Returns true only if:
|
|
94
|
+
* 1. The category exists
|
|
95
|
+
* 2. The category is active in the context (when predicate passes or is absent)
|
|
96
|
+
* 3. The word is in the category's word list
|
|
97
|
+
*
|
|
98
|
+
* @param category - Category name to check
|
|
99
|
+
* @param word - Word to match (case-insensitive)
|
|
100
|
+
* @param ctx - Current grammar context
|
|
101
|
+
* @returns true if word matches category in context
|
|
102
|
+
*/
|
|
103
|
+
match(category: string, word: string, ctx: GrammarContext): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Get all words in a category (for tooling/debugging).
|
|
106
|
+
* Returns empty set if category doesn't exist.
|
|
107
|
+
*
|
|
108
|
+
* @param category - Category name
|
|
109
|
+
* @returns Set of words in the category
|
|
110
|
+
*/
|
|
111
|
+
getWords(category: string): Set<string>;
|
|
112
|
+
/**
|
|
113
|
+
* Check if a category is active in the current context.
|
|
114
|
+
*
|
|
115
|
+
* @param category - Category name
|
|
116
|
+
* @param ctx - Current grammar context
|
|
117
|
+
* @returns true if category exists and its when predicate passes (or is absent)
|
|
118
|
+
*/
|
|
119
|
+
isActive(category: string, ctx: GrammarContext): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Check if a category exists (regardless of context).
|
|
122
|
+
*
|
|
123
|
+
* @param category - Category name
|
|
124
|
+
* @returns true if category has been defined
|
|
125
|
+
*/
|
|
126
|
+
hasCategory(category: string): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Get all defined category names (for tooling/debugging).
|
|
129
|
+
*
|
|
130
|
+
* @returns Array of category names
|
|
131
|
+
*/
|
|
132
|
+
getCategories(): string[];
|
|
133
|
+
/**
|
|
134
|
+
* Remove a category.
|
|
135
|
+
*
|
|
136
|
+
* @param category - Category name to remove
|
|
137
|
+
* @returns true if category was removed, false if it didn't exist
|
|
138
|
+
*/
|
|
139
|
+
removeCategory(category: string): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Clear all vocabulary categories.
|
|
142
|
+
*/
|
|
143
|
+
clear(): void;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Default implementation of IGrammarVocabularyProvider.
|
|
147
|
+
*
|
|
148
|
+
* Stores vocabulary categories with their words and context predicates.
|
|
149
|
+
* All word matching is case-insensitive.
|
|
150
|
+
*/
|
|
151
|
+
export declare class GrammarVocabularyProvider implements IGrammarVocabularyProvider {
|
|
152
|
+
private categories;
|
|
153
|
+
define(category: string, config: GrammarVocabularyConfig): void;
|
|
154
|
+
extend(category: string, words: string[]): void;
|
|
155
|
+
match(category: string, word: string, ctx: GrammarContext): boolean;
|
|
156
|
+
getWords(category: string): Set<string>;
|
|
157
|
+
isActive(category: string, ctx: GrammarContext): boolean;
|
|
158
|
+
hasCategory(category: string): boolean;
|
|
159
|
+
getCategories(): string[];
|
|
160
|
+
removeCategory(category: string): boolean;
|
|
161
|
+
clear(): void;
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=vocabulary-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocabulary-provider.d.ts","sourceRoot":"","sources":["../../src/grammar/vocabulary-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,wCAAwC;IACxC,KAAK,EAAE,MAAM,EAAE,CAAC;IAEhB;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,iDAAiD;IACjD,IAAI,EA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GAAG,OAAO;IAenE,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IASvC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO;IAcxD,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAItC,aAAa,IAAI,MAAM,EAAE;IAIzB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIzC,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Grammar Vocabulary Provider
|
|
4
|
+
* @description Context-aware vocabulary system for grammar pattern matching (ADR-082)
|
|
5
|
+
*
|
|
6
|
+
* This is distinct from vocabulary-contracts/VocabularyProvider which is for
|
|
7
|
+
* providing vocabulary entries to VocabularyRegistry. This system is specifically
|
|
8
|
+
* for context-aware vocabulary categories used in grammar slot matching.
|
|
9
|
+
*
|
|
10
|
+
* Vocabulary categories are registered with optional context predicates.
|
|
11
|
+
* The parser only considers a pattern if its vocabulary is active in the current context.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.GrammarVocabularyProvider = void 0;
|
|
15
|
+
/**
|
|
16
|
+
* Default implementation of IGrammarVocabularyProvider.
|
|
17
|
+
*
|
|
18
|
+
* Stores vocabulary categories with their words and context predicates.
|
|
19
|
+
* All word matching is case-insensitive.
|
|
20
|
+
*/
|
|
21
|
+
class GrammarVocabularyProvider {
|
|
22
|
+
categories = new Map();
|
|
23
|
+
define(category, config) {
|
|
24
|
+
if (this.categories.has(category)) {
|
|
25
|
+
throw new Error(`Vocabulary category '${category}' already exists. Use extend() to add words.`);
|
|
26
|
+
}
|
|
27
|
+
// Normalize words to lowercase
|
|
28
|
+
const normalizedWords = new Set(config.words.map(w => w.toLowerCase()));
|
|
29
|
+
this.categories.set(category, {
|
|
30
|
+
words: normalizedWords,
|
|
31
|
+
when: config.when
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
extend(category, words) {
|
|
35
|
+
const existing = this.categories.get(category);
|
|
36
|
+
if (!existing) {
|
|
37
|
+
throw new Error(`Vocabulary category '${category}' does not exist. Use define() first.`);
|
|
38
|
+
}
|
|
39
|
+
// Add normalized words
|
|
40
|
+
for (const word of words) {
|
|
41
|
+
existing.words.add(word.toLowerCase());
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
match(category, word, ctx) {
|
|
45
|
+
const config = this.categories.get(category);
|
|
46
|
+
if (!config) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
// Check context predicate
|
|
50
|
+
if (config.when && !config.when(ctx)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
// Check word (case-insensitive)
|
|
54
|
+
return config.words.has(word.toLowerCase());
|
|
55
|
+
}
|
|
56
|
+
getWords(category) {
|
|
57
|
+
const config = this.categories.get(category);
|
|
58
|
+
if (!config) {
|
|
59
|
+
return new Set();
|
|
60
|
+
}
|
|
61
|
+
// Return a copy to prevent external modification
|
|
62
|
+
return new Set(config.words);
|
|
63
|
+
}
|
|
64
|
+
isActive(category, ctx) {
|
|
65
|
+
const config = this.categories.get(category);
|
|
66
|
+
if (!config) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
// No predicate means always active
|
|
70
|
+
if (!config.when) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
return config.when(ctx);
|
|
74
|
+
}
|
|
75
|
+
hasCategory(category) {
|
|
76
|
+
return this.categories.has(category);
|
|
77
|
+
}
|
|
78
|
+
getCategories() {
|
|
79
|
+
return Array.from(this.categories.keys());
|
|
80
|
+
}
|
|
81
|
+
removeCategory(category) {
|
|
82
|
+
return this.categories.delete(category);
|
|
83
|
+
}
|
|
84
|
+
clear() {
|
|
85
|
+
this.categories.clear();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.GrammarVocabularyProvider = GrammarVocabularyProvider;
|
|
89
|
+
//# sourceMappingURL=vocabulary-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocabulary-provider.js","sourceRoot":"","sources":["../../src/grammar/vocabulary-provider.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAqJH;;;;;GAKG;AACH,MAAa,yBAAyB;IAC5B,UAAU,GAAG,IAAI,GAAG,EAGxB,CAAC;IAEL,MAAM,CAAC,QAAgB,EAAE,MAA+B;QACtD,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,wBAAwB,QAAQ,8CAA8C,CAAC,CAAC;QAClG,CAAC;QAED,+BAA+B;QAC/B,MAAM,eAAe,GAAG,IAAI,GAAG,CAC7B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CACvC,CAAC;QAEF,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE;YAC5B,KAAK,EAAE,eAAe;YACtB,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,QAAgB,EAAE,KAAe;QACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,wBAAwB,QAAQ,uCAAuC,CAAC,CAAC;QAC3F,CAAC;QAED,uBAAuB;QACvB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAgB,EAAE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,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,cAAc,CAAC,QAAgB;QAC7B,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK;QACH,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF;AAvFD,8DAuFC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sharpee/if-domain - Core domain model for Sharpee Interactive Fiction Platform
|
|
3
|
+
*
|
|
4
|
+
* This package contains the shared domain types, events, and contracts
|
|
5
|
+
* used throughout the Sharpee platform.
|
|
6
|
+
*/
|
|
7
|
+
export * from './events';
|
|
8
|
+
export * from './contracts';
|
|
9
|
+
export * from './changes';
|
|
10
|
+
export * from './sequencing';
|
|
11
|
+
export * from './language-provider';
|
|
12
|
+
export * from './parser-language-provider';
|
|
13
|
+
export * from './parser-contracts';
|
|
14
|
+
export * from './vocabulary-contracts';
|
|
15
|
+
export * from './grammar';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,UAAU,CAAC;AAGzB,cAAc,aAAa,CAAC;AAG5B,cAAc,WAAW,CAAC;AAG1B,cAAc,cAAc,CAAC;AAG7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAG3C,cAAc,oBAAoB,CAAC;AAGnC,cAAc,wBAAwB,CAAC;AAGvC,cAAc,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @sharpee/if-domain - Core domain model for Sharpee Interactive Fiction Platform
|
|
4
|
+
*
|
|
5
|
+
* This package contains the shared domain types, events, and contracts
|
|
6
|
+
* used throughout the Sharpee platform.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
// Domain events
|
|
24
|
+
__exportStar(require("./events"), exports);
|
|
25
|
+
// Domain contracts
|
|
26
|
+
__exportStar(require("./contracts"), exports);
|
|
27
|
+
// World state changes
|
|
28
|
+
__exportStar(require("./changes"), exports);
|
|
29
|
+
// Event sequencing
|
|
30
|
+
__exportStar(require("./sequencing"), exports);
|
|
31
|
+
// Language provider interfaces
|
|
32
|
+
__exportStar(require("./language-provider"), exports);
|
|
33
|
+
__exportStar(require("./parser-language-provider"), exports);
|
|
34
|
+
// Parser contracts
|
|
35
|
+
__exportStar(require("./parser-contracts"), exports);
|
|
36
|
+
// Vocabulary contracts
|
|
37
|
+
__exportStar(require("./vocabulary-contracts"), exports);
|
|
38
|
+
// Grammar system
|
|
39
|
+
__exportStar(require("./grammar"), exports);
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,gBAAgB;AAChB,2CAAyB;AAEzB,mBAAmB;AACnB,8CAA4B;AAE5B,sBAAsB;AACtB,4CAA0B;AAE1B,mBAAmB;AACnB,+CAA6B;AAE7B,+BAA+B;AAC/B,sDAAoC;AACpC,6DAA2C;AAE3C,mBAAmB;AACnB,qDAAmC;AAEnC,uBAAuB;AACvB,yDAAuC;AAEvC,iBAAiB;AACjB,4CAA0B"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language provider interface for Interactive Fiction
|
|
3
|
+
*
|
|
4
|
+
* This interface defines the contract for providing localized text,
|
|
5
|
+
* action patterns, and message formatting throughout the IF system.
|
|
6
|
+
*
|
|
7
|
+
* Implementations should handle:
|
|
8
|
+
* - Action patterns (verb synonyms)
|
|
9
|
+
* - Message text with parameter substitution
|
|
10
|
+
* - Localization and customization
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Structured help information for an action
|
|
14
|
+
*/
|
|
15
|
+
export interface ActionHelp {
|
|
16
|
+
/**
|
|
17
|
+
* Brief description of what the action does
|
|
18
|
+
*/
|
|
19
|
+
description: string;
|
|
20
|
+
/**
|
|
21
|
+
* Verb forms and patterns that trigger this action
|
|
22
|
+
* Extracted from the patterns array
|
|
23
|
+
*/
|
|
24
|
+
verbs: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Example commands showing usage
|
|
27
|
+
*/
|
|
28
|
+
examples: string[];
|
|
29
|
+
/**
|
|
30
|
+
* The one-line help summary (from help_<action> message)
|
|
31
|
+
* Format: "VERB/VERB - Description. Example: COMMAND"
|
|
32
|
+
*/
|
|
33
|
+
summary?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Language provider interface
|
|
37
|
+
*/
|
|
38
|
+
export interface LanguageProvider {
|
|
39
|
+
/**
|
|
40
|
+
* The language code this provider supports (e.g., 'en-us', 'es-es')
|
|
41
|
+
*/
|
|
42
|
+
readonly languageCode: string;
|
|
43
|
+
/**
|
|
44
|
+
* Get patterns/aliases for an action
|
|
45
|
+
* @param actionId The action identifier (e.g., 'if.action.taking')
|
|
46
|
+
* @returns Array of patterns or undefined if action not found
|
|
47
|
+
*/
|
|
48
|
+
getActionPatterns(actionId: string): string[] | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Get a message by ID with optional parameter substitution
|
|
51
|
+
* @param messageId The message identifier
|
|
52
|
+
* @param params Optional parameters for substitution
|
|
53
|
+
* @returns The formatted message
|
|
54
|
+
*/
|
|
55
|
+
getMessage(messageId: string, params?: Record<string, any>): string;
|
|
56
|
+
/**
|
|
57
|
+
* Check if a message exists
|
|
58
|
+
* @param messageId The message identifier
|
|
59
|
+
* @returns True if the message exists
|
|
60
|
+
*/
|
|
61
|
+
hasMessage(messageId: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Get structured help information for an action
|
|
64
|
+
* @param actionId The action identifier (e.g., 'if.action.taking')
|
|
65
|
+
* @returns Structured help information or undefined if not found
|
|
66
|
+
*/
|
|
67
|
+
getActionHelp?(actionId: string): ActionHelp | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Get all supported actions
|
|
70
|
+
* @returns Array of action IDs
|
|
71
|
+
*/
|
|
72
|
+
getSupportedActions?(): string[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Language provider registry interface
|
|
76
|
+
*/
|
|
77
|
+
export interface LanguageProviderRegistry {
|
|
78
|
+
/**
|
|
79
|
+
* Register a language provider
|
|
80
|
+
* @param provider The language provider to register
|
|
81
|
+
*/
|
|
82
|
+
register(provider: LanguageProvider): void;
|
|
83
|
+
/**
|
|
84
|
+
* Get a language provider by code
|
|
85
|
+
* @param languageCode The language code (e.g., 'en-us')
|
|
86
|
+
* @returns The provider or undefined if not found
|
|
87
|
+
*/
|
|
88
|
+
get(languageCode: string): LanguageProvider | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Get the default language provider
|
|
91
|
+
* @returns The default provider
|
|
92
|
+
* @throws Error if no default provider is set
|
|
93
|
+
*/
|
|
94
|
+
getDefault(): LanguageProvider;
|
|
95
|
+
/**
|
|
96
|
+
* Set the default language provider
|
|
97
|
+
* @param languageCode The language code to set as default
|
|
98
|
+
*/
|
|
99
|
+
setDefault(languageCode: string): void;
|
|
100
|
+
/**
|
|
101
|
+
* Get all registered language codes
|
|
102
|
+
* @returns Array of language codes
|
|
103
|
+
*/
|
|
104
|
+
getAvailableLanguages(): string[];
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=language-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-provider.d.ts","sourceRoot":"","sources":["../src/language-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;IAEhB;;OAEG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;IAEnB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B;;;;OAIG;IACH,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;IAE1D;;;;;OAKG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC;IAEpE;;;;OAIG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IAEvC;;;;OAIG;IACH,aAAa,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;IAEzD;;;OAGG;IACH,mBAAmB,CAAC,IAAI,MAAM,EAAE,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAE3C;;;;OAIG;IACH,GAAG,CAAC,YAAY,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;IAExD;;;;OAIG;IACH,UAAU,IAAI,gBAAgB,CAAC;IAE/B;;;OAGG;IACH,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvC;;;OAGG;IACH,qBAAqB,IAAI,MAAM,EAAE,CAAC;CACnC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Language provider interface for Interactive Fiction
|
|
4
|
+
*
|
|
5
|
+
* This interface defines the contract for providing localized text,
|
|
6
|
+
* action patterns, and message formatting throughout the IF system.
|
|
7
|
+
*
|
|
8
|
+
* Implementations should handle:
|
|
9
|
+
* - Action patterns (verb synonyms)
|
|
10
|
+
* - Message text with parameter substitution
|
|
11
|
+
* - Localization and customization
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
//# sourceMappingURL=language-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-provider.js","sourceRoot":"","sources":["../src/language-provider.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser contracts module exports
|
|
3
|
+
*
|
|
4
|
+
* These are the language-agnostic parser interfaces and types
|
|
5
|
+
* that can be implemented by language-specific parsers.
|
|
6
|
+
*/
|
|
7
|
+
export * from './parser-types';
|
|
8
|
+
export * from './parser-internals';
|
|
9
|
+
export * from './parser-factory';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parser-contracts/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Parser contracts module exports
|
|
4
|
+
*
|
|
5
|
+
* These are the language-agnostic parser interfaces and types
|
|
6
|
+
* that can be implemented by language-specific parsers.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./parser-types"), exports);
|
|
24
|
+
__exportStar(require("./parser-internals"), exports);
|
|
25
|
+
__exportStar(require("./parser-factory"), exports);
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/parser-contracts/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,iDAA+B;AAC/B,qDAAmC;AACnC,mDAAiC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates language-specific parser instances.
|
|
5
|
+
* The actual parser implementations are in separate packages
|
|
6
|
+
* and must be registered before use.
|
|
7
|
+
*/
|
|
8
|
+
import { Parser } from './parser-types';
|
|
9
|
+
/**
|
|
10
|
+
* Registry of parser constructors
|
|
11
|
+
* Language providers are passed as 'any' to avoid coupling
|
|
12
|
+
*/
|
|
13
|
+
type ParserConstructor = new (languageProvider: any) => Parser;
|
|
14
|
+
/**
|
|
15
|
+
* Parser factory for creating language-specific parsers
|
|
16
|
+
*/
|
|
17
|
+
export declare class ParserFactory {
|
|
18
|
+
/**
|
|
19
|
+
* Register a parser implementation for a language
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* import { EnglishParser } from '@sharpee/parser-en-us';
|
|
23
|
+
* ParserFactory.registerParser('en-US', EnglishParser);
|
|
24
|
+
*/
|
|
25
|
+
static registerParser(languageCode: string, parserClass: ParserConstructor): void;
|
|
26
|
+
/**
|
|
27
|
+
* Create a parser for the specified language
|
|
28
|
+
*
|
|
29
|
+
* @throws Error if no parser is registered for the language
|
|
30
|
+
*/
|
|
31
|
+
static createParser(languageCode: string, languageProvider: any): Parser;
|
|
32
|
+
/**
|
|
33
|
+
* Get list of registered language codes
|
|
34
|
+
*/
|
|
35
|
+
static getRegisteredLanguages(): string[];
|
|
36
|
+
/**
|
|
37
|
+
* Check if a parser is registered for a language
|
|
38
|
+
*/
|
|
39
|
+
static isLanguageRegistered(languageCode: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Clear all registered parsers (mainly for testing)
|
|
42
|
+
*/
|
|
43
|
+
static clearRegistry(): void;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=parser-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser-factory.d.ts","sourceRoot":"","sources":["../../src/parser-contracts/parser-factory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC;;;GAGG;AACH,KAAK,iBAAiB,GAAG,KAAK,gBAAgB,EAAE,GAAG,KAAK,MAAM,CAAC;AAI/D;;GAEG;AACH,qBAAa,aAAa;IACxB;;;;;;OAMG;IACH,MAAM,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,iBAAiB,GAAG,IAAI;IAWjF;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,GAAG,MAAM;IAwBxE;;OAEG;IACH,MAAM,CAAC,sBAAsB,IAAI,MAAM,EAAE;IAIzC;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;IAQ1D;;OAEG;IACH,MAAM,CAAC,aAAa,IAAI,IAAI;CAG7B"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Parser Factory
|
|
4
|
+
*
|
|
5
|
+
* Creates language-specific parser instances.
|
|
6
|
+
* The actual parser implementations are in separate packages
|
|
7
|
+
* and must be registered before use.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ParserFactory = void 0;
|
|
11
|
+
const parserRegistry = new Map();
|
|
12
|
+
/**
|
|
13
|
+
* Parser factory for creating language-specific parsers
|
|
14
|
+
*/
|
|
15
|
+
class ParserFactory {
|
|
16
|
+
/**
|
|
17
|
+
* Register a parser implementation for a language
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import { EnglishParser } from '@sharpee/parser-en-us';
|
|
21
|
+
* ParserFactory.registerParser('en-US', EnglishParser);
|
|
22
|
+
*/
|
|
23
|
+
static registerParser(languageCode, parserClass) {
|
|
24
|
+
const normalized = languageCode.toLowerCase();
|
|
25
|
+
parserRegistry.set(normalized, parserClass);
|
|
26
|
+
// Also register without region code
|
|
27
|
+
const langOnly = normalized.split('-')[0];
|
|
28
|
+
if (langOnly !== normalized && !parserRegistry.has(langOnly)) {
|
|
29
|
+
parserRegistry.set(langOnly, parserClass);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a parser for the specified language
|
|
34
|
+
*
|
|
35
|
+
* @throws Error if no parser is registered for the language
|
|
36
|
+
*/
|
|
37
|
+
static createParser(languageCode, languageProvider) {
|
|
38
|
+
const normalized = languageCode.toLowerCase();
|
|
39
|
+
// Try exact match first
|
|
40
|
+
let ParserClass = parserRegistry.get(normalized);
|
|
41
|
+
// Try language without region
|
|
42
|
+
if (!ParserClass) {
|
|
43
|
+
const langOnly = normalized.split('-')[0];
|
|
44
|
+
ParserClass = parserRegistry.get(langOnly);
|
|
45
|
+
}
|
|
46
|
+
if (!ParserClass) {
|
|
47
|
+
const available = Array.from(parserRegistry.keys()).sort();
|
|
48
|
+
throw new Error(`No parser registered for language: ${languageCode}. ` +
|
|
49
|
+
`Available languages: ${available.join(', ')}. ` +
|
|
50
|
+
`Register a parser using ParserFactory.registerParser().`);
|
|
51
|
+
}
|
|
52
|
+
return new ParserClass(languageProvider);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get list of registered language codes
|
|
56
|
+
*/
|
|
57
|
+
static getRegisteredLanguages() {
|
|
58
|
+
return Array.from(parserRegistry.keys()).sort();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Check if a parser is registered for a language
|
|
62
|
+
*/
|
|
63
|
+
static isLanguageRegistered(languageCode) {
|
|
64
|
+
const normalized = languageCode.toLowerCase();
|
|
65
|
+
if (parserRegistry.has(normalized))
|
|
66
|
+
return true;
|
|
67
|
+
const langOnly = normalized.split('-')[0];
|
|
68
|
+
return parserRegistry.has(langOnly);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Clear all registered parsers (mainly for testing)
|
|
72
|
+
*/
|
|
73
|
+
static clearRegistry() {
|
|
74
|
+
parserRegistry.clear();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.ParserFactory = ParserFactory;
|
|
78
|
+
//# sourceMappingURL=parser-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser-factory.js","sourceRoot":"","sources":["../../src/parser-contracts/parser-factory.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAUH,MAAM,cAAc,GAAG,IAAI,GAAG,EAA6B,CAAC;AAE5D;;GAEG;AACH,MAAa,aAAa;IACxB;;;;;;OAMG;IACH,MAAM,CAAC,cAAc,CAAC,YAAoB,EAAE,WAA8B;QACxE,MAAM,UAAU,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;QAC9C,cAAc,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QAE5C,oCAAoC;QACpC,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,IAAI,QAAQ,KAAK,UAAU,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7D,cAAc,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,YAAoB,EAAE,gBAAqB;QAC7D,MAAM,UAAU,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;QAE9C,wBAAwB;QACxB,IAAI,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAEjD,8BAA8B;QAC9B,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAA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