ebnf-railroad-visualizer
Version:
A web-based EBNF railroad diagram visualizer
61 lines (60 loc) • 2.33 kB
TypeScript
import { Grammar } from "./Grammar.js";
export declare class Diagram {
static readonly MAX_EXPANSION_DEPTH: number;
readonly grammar: Grammar;
private readonly pathStack;
private expandingNtsPaths;
private collectPaths;
private startSymbolName;
private constructor();
/**
* Generate a diagram from a grammar
* @param {string} grammarString The grammar as a string
* @param {string?} startSymbolName The name of the start symbol. If not provided the first production is used
* @returns {Diagram} The diagram
*/
static fromString(grammarString: string, startSymbolName?: string): Diagram;
/**
* Generate a diagram from a grammar
* @param {Grammar} grammar The grammar
* @param {string?} startSymbolName The name of the start symbol. If not provided the first production is used
* @param startSymbolName The name of the start symbol. If not provided the first production is used
* @returns {Diagram} The diagram
*/
static fromGrammar(grammar: Grammar, startSymbolName?: string): Diagram;
/**
* Generate a diagram from a production
* @returns {any} The diagram
*/
private generateDiagram;
private forProduction;
private forExpression;
private forTerm;
private generateBasicSequence;
private forFactor;
private generateFrom;
/**
* A diagram in SVG format
* @param {Set<number[]>} expandingNtsPaths The paths of the NTS that should be expanded
* @returns {string} The diagram in SVG format
*/
toSvg(expandingNtsPaths?: Set<number[]>): string;
/**
* Inject markers into the SVG.
* It includes some SVG madness to inject markers into the correct paths. With quite a bunch of magic values that I found out by trial and error.
* @param {string} svg The SVG string with injected markers
* @returns {string} The SVG string with injected markers
*/
private injectMarkers;
/**
* Get all NTS paths that should be expanded.
* Still adhears to the MAX_EXPANSION_DEPTH limit.
* @returns {Set<number[]>} The paths of the NTS that should be expanded
*/
getAllNtsPaths(): Set<number[]>;
/**
* A diagram in string format
* @returns {string} The diagram in string format
*/
toString(): string;
}