/** * English Parser Implementation * * This parser handles English-specific grammar patterns and preserves all information * in rich structured commands. */ import { Parser, ParserOptions, Token as InternalToken, InternalParseResult, ParserLanguageProvider, VerbVocabulary, VocabularyEntry, Constraint } from '@sharpee/if-domain'; import type { IParsedCommand, IValidatedCommand, IParseError as CoreParseError } from '@sharpee/world-model'; import type { ISystemEvent, Result } from '@sharpee/core'; import { GrammarBuilder } from '@sharpee/if-domain'; import { PronounContextManager } from './pronoun-context'; type CommandResult = Result; /** * English parser with rich information preservation */ export declare class EnglishParser implements Parser { private options; private language; private onDebugEvent?; private platformEventEmitter?; private grammarEngine; private worldContext; /** Pronoun context manager for "it", "them", "him", "her" resolution (ADR-089) */ private pronounContext; constructor(language: ParserLanguageProvider, options?: ParserOptions); /** * Initialize vocabulary from language provider */ private initializeVocabulary; /** * Set debug event callback */ setDebugCallback(callback: ((event: ISystemEvent) => void) | undefined): void; /** * Set platform event emitter for parser debugging */ setPlatformEventEmitter(emitter: ((event: any) => void) | undefined): void; /** * Set the world context for scope constraint evaluation */ setWorldContext(world: any, actorId: string, currentLocation: string): void; /** * Emit a platform debug event */ private emitPlatformEvent; /** * Register additional verbs after parser creation * Used for story-specific vocabulary */ registerVerbs(verbs: VerbVocabulary[]): void; /** * Register additional vocabulary entries * More generic than registerVerbs - can handle any part of speech */ registerVocabulary(entries: VocabularyEntry[]): void; /** * Parse input text into structured command with rich information */ parse(input: string): CommandResult; /** * Parse input that may contain multiple commands separated by periods or commas. * Returns an array of parsed commands (or errors). * * Period chaining: * - "take sword. go north." → [take sword, go north] * * Comma chaining (only when verb detected after comma): * - "take sword, drop it" → [take sword, drop it] (verb after comma) * - "take knife, lamp" → single command with list (no verb after comma) * * Examples: * - "take sword. go north." → [take sword, go north] * - "take sword" → [take sword] * - "take sword. invalid. go north" → [take sword, error, go north] */ parseChain(input: string): CommandResult[]; /** * Split a segment on commas only if a verb is detected after the comma. * "take knife, drop lamp" → ["take knife", "drop lamp"] (verb after comma) * "take knife, lamp" → ["take knife, lamp"] (no verb, treat as list) */ private splitOnCommasIfChain; /** * Split input on periods, preserving quoted strings. * Handles edge cases like trailing periods and empty segments. */ private splitOnPeriods; /** * Tokenize input with rich information preservation */ private tokenizeRich; /** * Find possible command structures in the tokens */ private findCommandStructures; /** * Convert a grammar match to a RichCandidate */ private convertGrammarMatch; /** * Register story-specific grammar rules * @deprecated Use getStoryGrammar() for full API */ registerGrammar(pattern: string, action: string, constraints?: Record): void; /** * Get the grammar builder for story-specific rules. * Stories use this to define custom grammar patterns. * * ADR-084: Returns the grammar builder directly instead of a wrapper, * giving stories full access to all PatternBuilder methods. */ getStoryGrammar(): GrammarBuilder; /** * Get candidate interpretations for a token */ private getTokenCandidates; /** * Old tokenize method for compatibility */ tokenize(input: string): InternalToken[]; /** * Parse with errors for testing compatibility */ parseWithErrors(input: string, options?: ParserOptions): InternalParseResult; /** * Add a custom verb to the parser vocabulary * @param actionId The action ID this verb maps to * @param verbs Array of verb forms to recognize * @param pattern Optional grammar pattern for the verb (e.g., 'VERB_OBJ') * @param prepositions Optional prepositions this verb can use */ addVerb(actionId: string, verbs: string[], pattern?: string, prepositions?: string[]): void; /** * Add a custom noun/synonym to the parser vocabulary * @param word The word to add * @param canonical The canonical form it maps to */ addNoun(word: string, canonical: string): void; /** * Add a custom adjective to the parser vocabulary * @param word The adjective to add */ addAdjective(word: string): void; /** * Add a custom preposition to the parser vocabulary * @param word The preposition to add */ addPreposition(word: string): void; /** * Build a detailed parse error from failure analysis */ private buildParseError; /** * Update pronoun context after a successful command execution * Called by the engine after command execution succeeds * @param command The validated command with resolved entity IDs * @param turnNumber Current turn number */ updatePronounContext(command: IValidatedCommand, turnNumber: number): void; /** * Register an entity that was mentioned in context * Used when entities are referenced outside of standard parsing * @param entityId The entity's ID * @param text How the player referred to it * @param turnNumber Current turn number */ registerPronounEntity(entityId: string, text: string, turnNumber: number): void; /** * Reset the pronoun context * Called on game restart or when context should be cleared */ resetPronounContext(): void; /** * Get the last successfully parsed command * Used for "again" / "g" command support */ getLastCommand(): IParsedCommand | null; /** * Get the pronoun context manager (for testing/debugging) */ getPronounContextManager(): PronounContextManager; } export {}; //# sourceMappingURL=english-parser.d.ts.map