/** * Type annotation parser for Dvala. * * Parses type annotation strings like "(Number, Number) -> Number" into * Type values. Used for builtin function type signatures and eventually * for user-written type annotations in source code. * * Grammar (simplified): * Type = UnionType * UnionType = InterType ("|" InterType)* * InterType = PrefixType ("&" PrefixType)* * PrefixType = "!" PrefixType | PostfixType * PostfixType= PrimaryType ("[]")* * PrimaryType= "(" FuncOrParen ")" | "[" TupleType "]" | "{" RecordType "}" * | "Number" | "String" | "Boolean" | "Null" | "Regex" * | "Unknown" | "Never" * | ":" identifier // atom type * | number | string | "true" | "false" // literal types * | uppercase-identifier // type variable (A, B, T, etc.) * FuncOrParen= ParamList [":" Type] "->" [EffectSet] Type // function type * | ParamList "->" identifier "is" Type // type guard * | Type // parenthesized type * ParamList = Param ("," Param)* * Param = Type | identifier ["?"] ":" Type | "..." Type[] | "..." identifier ":" Type[] * EffectSet = "@{" [effectName ("," effectName)*] ["," "..."] "}" */ import type { Type } from './types'; export interface TypeAliasRegistrySnapshot { entries: [string, { params: string[]; body: string; }][]; } /** Register a type alias. Called by typecheck.ts from parsed AST. */ export declare function registerTypeAlias(name: string, params: string[], body: string): void; /** Reset user-registered type aliases (called between typecheck passes). */ export declare function resetTypeAliases(): void; /** Snapshot the current alias registry so nested import typechecking can restore it. */ export declare function snapshotTypeAliases(): TypeAliasRegistrySnapshot; /** Restore a previously captured alias registry snapshot. */ export declare function restoreTypeAliases(snapshot: TypeAliasRegistrySnapshot): void; /** * Parse a type annotation string into a Type value. * Throws on syntax errors. */ export declare function parseTypeAnnotation(input: string): Type; /** * Parse a function type annotation string. Returns the parsed type * plus any type guard info (parameter name and narrowed type). */ export interface ParsedFunctionType { type: Type; /** If the function is a type guard, the parameter name being narrowed. */ guardParam?: string; /** If the function is a type guard, the type it narrows to. */ guardType?: Type; } export declare function parseFunctionTypeAnnotation(input: string): ParsedFunctionType; export declare class TypeParseError extends Error { input: string; position: number; constructor(message: string, input: string, position: number); }