UNPKG

antlr-ng

Version:

Next generation ANTLR Tool

37 lines (36 loc) 1.39 kB
/** * A generic graph with edges; Each node has a single Object payload. * This is only used to topologically sort a list of file dependencies at the moment. */ export declare class Graph { static Node: { new (payload: string): { payload: string; edges: /*elided*/ any[]; addEdge(n: /*elided*/ any): void; toString(): string; }; }; /** Map from node payload to node containing it */ protected nodes: Map<string, { payload: string; edges: /*elided*/ any[]; addEdge(n: /*elided*/ any): void; toString(): string; }>; addEdge(a: string, b: string): void; getNode(a: string): InstanceType<typeof Graph.Node>; /** * DFS-based topological sort. A valid sort is the reverse of the post-order DFA traversal. Amazingly simple * but true. For sorting, I'm not following convention here since ANTLR needs the opposite. Here's what I * assume for sorting: * * If there exists an edge u -> v then u depends on v and v must happen before u. * * So if this gives non-reversed post order traversal, I get the order I want. * * @returns A list of node payloads in topological order. */ sort(): string[]; dfs(n: InstanceType<typeof Graph.Node>, visited: Set<InstanceType<typeof Graph.Node>>, sorted: string[]): void; }