@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
55 lines (54 loc) • 3.07 kB
TypeScript
import type { AstIdMap } from './decorate';
import type { DataflowGraph } from '../../../../../dataflow/graph/graph';
/** The type of the id assigned to each node. Branded to avoid problematic usages with other string or numeric types. */
export type NodeId<T extends string | number = string | number> = T & {
__brand?: 'node-id';
};
/**
* A variant of {@link NodeId} that represents built-in functions or operators. The string is prefixed with `built-in:` to avoid confusion with other node ids.
*/
export type BuiltIn<T extends string = string> = `built-in:${T}`;
/**
* The type of the id assigned to each node. Branded to avoid problematic usages with other string or numeric types.
* The default ids are numeric, but we use a branded type to avoid confusion with other numeric types.
* Custom ids or scoped ids can be strings, but they will be normalized to numbers if they are numeric strings.
*/
export declare const NodeId: {
readonly name: "NodeId";
/**
* Normalizes a node id by converting numeric strings to numbers.
* This allows us to use numeric ids without storing them as strings, while still allowing custom string ids if needed.
*/
readonly normalize: (this: void, id: NodeId) => NodeId;
/**
* The prefix used for built-in function or operator ids.
*/
readonly builtInPrefix: "built-in:";
/**
* Checks if a given node id is a built-in function or operator id by checking if it is a string that starts with the built-in prefix.
* @see {@link toBuiltIn} - to convert a built-in function or operator name to a built-in id
* @see {@link fromBuiltIn} - to recover the built-in function or operator name from a built-in id
*/
readonly isBuiltIn: (this: void, id: BuiltIn | NodeId | undefined) => id is BuiltIn;
/**
* Converts a built-in function or operator name to a built-in id by prefixing it with the built-in prefix.
* @see {@link isBuiltIn} - to check if a given node id is a built-in function or operator id
* @see {@link fromBuiltIn} - to recover the built-in function or operator name from a built-in id
*/
readonly toBuiltIn: <T extends string>(this: void, name: T) => BuiltIn<T>;
/**
* Recovers the built-in function or operator name from a built-in id by removing the built-in prefix.
* @see {@link isBuiltIn} - to check if a given node id is a built-in function or operator id
* @see {@link toBuiltIn} - to convert a built-in function or operator name to a built-in id
*/
readonly fromBuiltIn: <T extends string>(this: void, id: BuiltIn<T>) => T;
};
/**
* Recovers the lexeme of a {@link RNode|node} from its id in the {@link AstIdMap|id map}.
* @see {@link recoverContent} - to recover the content of a node
*/
export declare function recoverName(id: NodeId, idMap?: AstIdMap): string | undefined;
/**
* Recovers the content of a {@link RNode|node} from its id in the {@link DataflowGraph|dataflow graph}.
*/
export declare function recoverContent(id: NodeId, graph: DataflowGraph): string | undefined;