/** * Value Extractor Interface - Pluggable Tokenization * * Extracts typed values from input strings. * DSLs can provide custom extractors for their domain-specific syntax. * * Includes the ContextAwareExtractor extension for extractors that need * access to tokenizer state (keyword maps, morphological normalizers, etc.). */ import type { MorphologicalNormalizer } from '../core/tokenization/morphology/types'; /** * Keyword entry for tokenizer - maps native word to normalized English form. * Re-exported here so ContextAwareExtractor consumers can use it without * depending on the base-tokenizer module directly. */ export interface KeywordEntry { readonly native: string; readonly normalized: string; } /** * Extraction result with value and consumed length. */ export interface ExtractionResult { /** The extracted value */ readonly value: string; /** Number of characters consumed */ readonly length: number; /** Optional metadata about the extraction */ readonly metadata?: Record; } /** * Value extractor - identifies and extracts typed values from input. */ export interface ValueExtractor { /** Name of this extractor (for debugging) */ readonly name: string; /** * Check if this extractor can handle input at position. * * @param input - Full input string * @param position - Current position * @returns True if this extractor should try * * @example * // CSS selector extractor * canExtract('#button', 0) // → true (starts with #) * canExtract('button', 0) // → false */ canExtract(input: string, position: number): boolean; /** * Extract value from input at position. * * @param input - Full input string * @param position - Start position * @returns Extraction result or null if extraction failed * * @example * extract('#button', 0) // → { value: '#button', length: 7 } * extract('button', 0) // → null (can't extract CSS selector) */ extract(input: string, position: number): ExtractionResult | null; } /** * String literal extractor - handles quoted strings. */ export declare class StringLiteralExtractor implements ValueExtractor { readonly name = "string-literal"; canExtract(input: string, position: number): boolean; extract(input: string, position: number): ExtractionResult | null; } /** * Number extractor - handles integers and floats. */ export declare class NumberExtractor implements ValueExtractor { readonly name = "number"; canExtract(input: string, position: number): boolean; extract(input: string, position: number): ExtractionResult | null; } /** * Identifier extractor - handles variable/property names. */ export declare class IdentifierExtractor implements ValueExtractor { readonly name = "identifier"; canExtract(input: string, position: number): boolean; extract(input: string, position: number): ExtractionResult | null; } /** * Unicode identifier extractor - handles non-Latin scripts. * * Matches contiguous runs of Unicode letters, numbers, and combining marks * that aren't ASCII (ASCII identifiers are handled by IdentifierExtractor). * Essential for DSLs supporting CJK, Arabic, Cyrillic, Devanagari, etc. */ export declare class UnicodeIdentifierExtractor implements ValueExtractor { readonly name = "unicode-identifier"; canExtract(input: string, position: number): boolean; extract(input: string, position: number): ExtractionResult | null; } /** * Latin Extended identifier extractor — handles Latin-script languages with * diacritics (Spanish ñ/á/é/í/ó/ú; French é/à/ù/ç; Turkish ç/ş/ı/ü/ğ/ö; * Portuguese ã/õ; German ä/ö/ü/ß; etc). * * Use this in addition to (or instead of) the default `IdentifierExtractor` * for any tokenizer whose language is Latin-script and may contain diacritic * characters in identifiers. Without it, words like `añadir` tokenize as * `["a", "ñadir"]` because the default ASCII extractor stops at `ñ` and the * Unicode extractor only kicks in when a token *starts* with a non-ASCII * character. * * Matches contiguous runs of `/[\p{L}\p{N}_-]/u` — any Unicode letter or * number, plus underscore and hyphen. */ export declare class LatinExtendedIdentifierExtractor implements ValueExtractor { readonly name = "latin-extended-identifier"; canExtract(input: string, position: number): boolean; extract(input: string, position: number): ExtractionResult | null; } export declare class CssSelectorExtractor implements ValueExtractor { readonly name = "css-selector"; canExtract(input: string, position: number): boolean; extract(input: string, position: number): ExtractionResult | null; } /** * Whitespace extractor - handles spaces, tabs, newlines. */ export declare class WhitespaceExtractor implements ValueExtractor { readonly name = "whitespace"; canExtract(input: string, position: number): boolean; extract(input: string, position: number): ExtractionResult | null; } /** * Tokenizer context provided to context-aware extractors. * Gives extractors access to tokenizer state without tight coupling. */ export interface TokenizerContext { /** ISO 639-1 language code */ readonly language: string; /** Text direction */ readonly direction: 'ltr' | 'rtl'; /** * Look up a keyword by its native form. * Returns keyword entry with normalized form, or undefined if not found. */ lookupKeyword(native: string): KeywordEntry | undefined; /** * Check if a word is a known keyword. */ isKeyword(native: string): boolean; /** * Check if a known keyword starts at the given position. * Useful for word boundary detection in non-space languages. */ isKeywordStart(input: string, position: number): boolean; /** * Like `isKeywordStart`, but only true when the keyword match ends at a * word boundary (end of input or a char rejected by `isWordChar`). * Space-delimited languages must use this for word-walk break checks — * the keyword table includes English canonical fallbacks (me, it, you, …), * so the raw check splits native words mid-word (e.g. Quechua ñit'iy * contains "it"). Optional for backward compatibility with hand-rolled * contexts; callers should treat absence as "no boundary keyword here". */ isKeywordStartAtBoundary?(input: string, position: number, isWordChar?: (char: string) => boolean): boolean; /** * Optional morphological normalizer for this language. */ readonly normalizer?: MorphologicalNormalizer; } /** * Context-aware extractor - has access to tokenizer state. * * Use this for extractors that need: * - Keyword lookup (for normalization) * - Morphological analysis (for conjugation handling) * - Language-specific rules * * For stateless extractors (strings, numbers, operators), use ValueExtractor. */ export interface ContextAwareExtractor extends ValueExtractor { /** * Set the tokenizer context. * Called once by the tokenizer during registration. */ setContext(context: TokenizerContext): void; } /** * Type guard to check if an extractor is context-aware. */ export declare function isContextAwareExtractor(extractor: ValueExtractor | ContextAwareExtractor): extractor is ContextAwareExtractor; /** * Create a TokenizerContext from a tokenizer instance. * Works with any object that exposes the required methods. */ export declare function createTokenizerContext(tokenizer: { language: string; direction: 'ltr' | 'rtl'; lookupKeyword(native: string): KeywordEntry | undefined; isKeyword(native: string): boolean; isKeywordStart(input: string, position: number): boolean; isKeywordStartAtBoundary?(input: string, position: number, isWordChar?: (char: string) => boolean): boolean; normalizer?: MorphologicalNormalizer; }): TokenizerContext; //# sourceMappingURL=value-extractor.d.ts.map