UNPKG

typir

Version:

General purpose type checking library

71 lines 5.61 kB
/****************************************************************************** * Copyright 2024 TypeFox GmbH * This program and the accompanying materials are made available under the * terms of the MIT License, which is available in the project root. ******************************************************************************/ import { Type } from '../graph/type-node.js'; import { TypeInitializer } from '../initialization/type-initializer.js'; import { TypeInferenceRule, TypeInferenceRuleOptions } from '../services/inference.js'; import { ValidationProblemAcceptor, ValidationRule, ValidationRuleOptions } from '../services/validation.js'; import { TypirSpecifics, TypirServices } from '../typir.js'; /** * Common interface of all problems/errors/messages which should be shown to users of DSLs which are type-checked with Typir. * This approach makes it easier to introduce additional errors by users of Typir, compared to a union type, e.g. export type TypirProblem = ValueConflict | IndexedTypeConflict | ... */ export interface TypirProblem { readonly $problem: string; } export declare function isSpecificTypirProblem(problem: unknown, $problem: string): problem is TypirProblem; export type Types = Type | Type[]; export type Names = string | string[]; export type TypeInitializers<T extends Type, Specifics extends TypirSpecifics> = TypeInitializer<T, Specifics> | Array<TypeInitializer<T, Specifics>>; export type NameTypePair = { name: string; type: Type; }; export declare function isNameTypePair(type: unknown): type is NameTypePair; /** A pair of a rule for type inference with its additional options. */ export interface ValidationRuleWithOptions<Specifics extends TypirSpecifics, T extends Specifics['LanguageType'] = Specifics['LanguageType']> { rule: ValidationRule<Specifics, T>; options: Partial<ValidationRuleOptions>; } export declare function bindValidateCurrentTypeRule<TypeType extends Type, Specifics extends TypirSpecifics, T extends Specifics['LanguageType'] = Specifics['LanguageType']>(rule: InferCurrentTypeRule<TypeType, Specifics, T>, type: TypeType): ValidationRuleWithOptions<Specifics, T> | undefined; /** * These options are used for pre-defined valiations in order to enable the user to decide, * how the created pre-defined valiation should be registered. */ export interface RegistrationOptions { /** * 'MYSELF' indicates, that the caller is responsible to register the validation rule, * otherwise the given options are used to register the return validation rule now. */ registration: 'MYSELF' | Partial<ValidationRuleOptions>; } /** A pair of a rule for type inference with its additional options. */ export interface InferenceRuleWithOptions<Specifics extends TypirSpecifics, T extends Specifics['LanguageType'] = Specifics['LanguageType']> { rule: TypeInferenceRule<Specifics, T>; options: Partial<TypeInferenceRuleOptions>; } export declare function optionsBoundToType<T extends Partial<TypeInferenceRuleOptions> | Partial<ValidationRuleOptions>>(options: T, type: Type | undefined): T; export declare function ruleWithOptionsBoundToType<Specifics extends TypirSpecifics, T extends Specifics['LanguageType'] = Specifics['LanguageType']>(rule: InferenceRuleWithOptions<Specifics, T>, type: Type | undefined): InferenceRuleWithOptions<Specifics, T>; /** * An inference rule which is dedicated for inferrring a certain type. * This utility type is often used for inference rules which are annotated to the declaration of a type. * At least one of the properties needs to be specified. */ export interface InferCurrentTypeRule<TypeType extends Type, Specifics extends TypirSpecifics, T extends Specifics['LanguageType'] = Specifics['LanguageType']> { languageKey?: string | string[]; filter?: (languageNode: Specifics['LanguageType']) => languageNode is T; matching?: (languageNode: T, typeToInfer: TypeType) => boolean; /** * This validation will be applied to all language nodes for which the current type is inferred according to this inference rule. * This validation is specific for this inference rule and this inferred type. */ validation?: InferCurrentTypeValidationRule<TypeType, Specifics, T> | Array<InferCurrentTypeValidationRule<TypeType, Specifics, T>>; skipThisRuleIfThisTypeAlreadyExists?: boolean | ((existingType: TypeType) => boolean); } export type InferCurrentTypeValidationRule<TypeType extends Type, Specifics extends TypirSpecifics, T extends Specifics['LanguageType'] = Specifics['LanguageType']> = (languageNode: T, inferredType: TypeType, accept: ValidationProblemAcceptor<Specifics>, typir: TypirServices<Specifics>) => void; export declare function skipInferenceRuleForExistingType<TypeType extends Type, Specifics extends TypirSpecifics, T extends Specifics['LanguageType'] = Specifics['LanguageType']>(inferenceRule: InferCurrentTypeRule<TypeType, Specifics, T>, newType: TypeType, existingType: TypeType): boolean; export declare function bindInferCurrentTypeRule<TypeType extends Type, Specifics extends TypirSpecifics, T extends Specifics['LanguageType'] = Specifics['LanguageType']>(rule: InferCurrentTypeRule<TypeType, Specifics, T>, type: TypeType): InferenceRuleWithOptions<Specifics, T>; export declare function registerInferCurrentTypeRules<TypeType extends Type, Specifics extends TypirSpecifics>(rules: InferCurrentTypeRule<TypeType, Specifics> | Array<InferCurrentTypeRule<TypeType, Specifics>> | undefined, type: TypeType, services: TypirServices<Specifics>): void; //# sourceMappingURL=utils-definitions.d.ts.map