UNPKG

@bscotch/gml-parser

Version:

A parser for GML (GameMaker Language) files for programmatic manipulation and analysis of GameMaker projects.

152 lines 7.68 kB
import { Flags } from './signifiers.flags.js'; import { Signifier } from './signifiers.js'; import { type KnownOrGenerics, type KnownTypesMap } from './types.feather.js'; import { PrimitiveName, withableTypes } from './types.primitives.js'; export type AnyType = Type<'Any'>; export type ArrayType = Type<'Array'>; export type BoolType = Type<'Bool'>; export type EnumType = Type<'Enum'>; export type FunctionType = Type<'Function'>; export type PointerType = Type<'Pointer'>; export type RealType = Type<'Real'>; export type StringType = Type<'String'>; export type StructType = Type<'Struct'>; export type UndefinedType = Type<'Undefined'>; export type UnknownType = Type<'Unknown'>; export type WithableType = Type<(typeof withableTypes)[number]>; /** * A stable entity that represents a type. It should be used * as the referenced container for any type information, so * that the types can be changed within the container without * breaking references. */ export declare class TypeStore<T extends PrimitiveName = PrimitiveName> extends Flags { readonly $tag = "TypeStore"; protected _types: Type<T>[]; constructor(); /** If this store has only one type, its kind. Else throws. */ get kind(): "Real" | "Undefined" | "Enum" | "Function" | "Array" | "Bool" | "Pointer" | "String" | "Struct" | "ArgumentIdentity" | "Any" | "Asset.GMAnimCurve" | "Asset.GMAudioGroup" | "Asset.GMFont" | "Asset.GMObject" | "Asset.GMParticleSystem" | "Asset.GMPath" | "Asset.GMRoom" | "Asset.GMScript" | "Asset.GMSequence" | "Asset.GMShader" | "Asset.GMSound" | "Asset.GMSprite" | "Asset.GMTileSet" | "Asset.GMTimeline" | "Asset.Script" | "Id.AudioEmitter" | "Id.AudioListener" | "Id.AudioSyncGroup" | "Id.BackgroundElement" | "Id.BinaryFile" | "Id.Buffer" | "Id.Camera" | "Id.DsGrid" | "Id.DsList" | "Id.DsMap" | "Id.DsPriority" | "Id.DsQueue" | "Id.DsStack" | "Id.ExternalCall" | "Id.Gif" | "Id.Instance" | "Id.Layer" | "Id.MpGrid" | "Id.ParticleEmitter" | "Id.ParticleSystem" | "Id.ParticleType" | "Id.PhysicsIndex" | "Id.PhysicsParticleGroup" | "Id.Sampler" | "Id.SequenceElement" | "Id.Socket" | "Id.Sound" | "Id.SpriteElement" | "Id.Surface" | "Id.TextFile" | "Id.Texture" | "Id.TileElementId" | "Id.TileMapElement" | "Id.TimeSource" | "Id.Uniform" | "Id.VertexBuffer" | "Id.VertexFormat" | "Mixed" | "EnumMember" | "Unknown" | "Never" | "InstanceType" | "ObjectType" | "StaticType"; get type(): Type<T>[]; set type(types: Type<T> | Type<T>[] | undefined); get hasTypes(): boolean; get constructs(): StructType[]; get items(): TypeStore[]; get returns(): TypeStore[]; /** * Should be used sparingly, since it means we're adding types in multiple steps instead of all at once. */ addType(type: Type<T> | Type<T>[]): this; narrows(other: TypeStore | Type | Type[]): boolean; toFeatherString(): string; } export declare class Type<T extends PrimitiveName = PrimitiveName> { protected _kind: T; readonly $tag = "Type"; name: string | undefined; description: string | undefined; /** Signifiers associated with this type. */ _signifier: Signifier | undefined; /** * If set, then this Type is treated as a subset of the parent. * It will only "match" another type if that type is in its * parent somewhere. Useful for struct/constructor inheritence, as well * as for e.g. representing a subset of Real constants in a type. */ protected _extends: Type | undefined; protected _derived: Set<Type> | undefined; protected flags: number; /** Named members of Structs and Enums */ protected _members: Map<string, Signifier> | undefined; /** Types of the items found in arrays and various ds types, or the fallback type found in Structs */ items: TypeStore | undefined; /** * For functions, the local variables declared within the function. * A subset of these will be parameters, which are also signifiers. */ local: Type<'Struct'> | undefined; /** * If this is a constructor function, then this is the * type of the struct that it constructs. * Otherwise it's the self-context of the function */ self: WithableType | undefined; returns: TypeStore | undefined; constructor(_kind: T); protected setFlag(flag: number, value: boolean): void; protected getFlag(flag: number): boolean; /** * Native and primitive types are typically read-only once * they've been defined. This property should be set once a type * is intended to be immutable. */ get isReadonly(): boolean; set isReadonly(value: boolean); /** * If this is a type used as a generic, then this will be true */ get isGeneric(): boolean; set isGeneric(value: boolean); get isConstructor(): boolean; set isConstructor(value: boolean); get kind(): PrimitiveName; set kind(newKind: PrimitiveName); get signifier(): Signifier | undefined; set signifier(signifier: Signifier); get extends(): Type | undefined; set extends(type: Type | undefined); listDerived(recursive?: boolean): Type[]; get canBeSelf(): boolean; /** If this type narrows `other` type, returns `true` */ narrows(other: Type | Type[] | TypeStore): boolean; /** Get this type as a Feather-compatible string */ toFeatherString(): string; get code(): string; get details(): string; get isFunction(): boolean; setReturnType(type: Type | TypeStore | (Type | TypeStore)[]): this; /** Prefer `setReturnType` where possible */ addReturnType(type: Type | Type[]): this; listParameters(): (Signifier | undefined)[]; getParameter(name: string): Signifier | undefined; getParameter(idx: number): Signifier | undefined; /** A parameter is a special type of local variable. */ addParameter(idx: number, nameOrParam: string | Signifier, options?: { type?: Type | Type[]; optional?: boolean; }): Signifier; truncateParameters(count: number): void; totalMembers(excludeParents?: boolean): number; listMembers(excludeParents?: boolean): Signifier[]; getMember(name: string, excludeParents?: boolean): Signifier | undefined; /** For container types that have named members, like Structs and Enums */ addMember(newMember: Signifier | string, options?: { type?: Type | Type[]; writable?: boolean; override?: boolean; }): Signifier | undefined; protected replaceMemberInChildren(member: Signifier): void; removeMember(name: string): void; /** * For container types that have non-named members, like arrays and DsTypes. * Can also be used for default Struct values. */ addItemType(type: Type): this; /** * For container types that have non-named members, like arrays and DsTypes. * Can also be used for default Struct values. */ setItemType(type: Type): this; /** * Create a derived type: of the same kind, pointing to * this type as its parent. */ derive(): Type<T>; named(name: string | undefined): this; describe(description: string | undefined): this; genericize(): this; /** Given a Feather-compatible type string, get a fully parsed type. */ static fromFeatherString(typeString: string, knownTypes: KnownTypesMap | KnownOrGenerics[], addMissing: boolean): Type[]; static get Any(): Type<"Any">; static get Real(): Type<"Real">; static get String(): Type<"String">; static get Bool(): Type<"Bool">; static get Undefined(): Type<"Undefined">; static get Struct(): Type<"Struct">; static get Function(): Type<"Function">; } //# sourceMappingURL=types.d.ts.map