@light0x00/parser-generator
Version:
A Parser Generator
77 lines (76 loc) • 2.73 kB
TypeScript
import { ASTMaker, ILexer } from "@light0x00/parser-definition";
export declare type Terminal = Object;
export declare type Symbol = NonTerminal | Terminal;
export declare class NonTerminal extends Array<Production> {
name: string;
constructor(name: string, prods?: Production[]);
get prods(): Production[];
set prods(prods: Production[]);
toString(): string;
addProd(id: number, body: Symbol[]): Production;
}
export declare class Production extends Array<Symbol> {
id: number;
name: string;
nonTerminal: NonTerminal;
makeAST: ASTMaker;
private _precedence;
private _leftAssociation;
static DefaultMakeAST: () => never;
constructor(id: number, non_terminal: NonTerminal, body: Symbol[], makeAST?: ASTMaker, precedence?: number, leftAssociation?: boolean);
get leftAssoc(): boolean;
get prec(): number;
isEpsilon(): boolean;
toString(): string;
}
export interface IParser {
parse(lexer: ILexer): void;
}
export interface IGrammar {
NTS(): NonTerminal[];
Prods(): Production[];
startNT(): NonTerminal;
}
export declare type RawSimpleGrammar = Array<Array<NonTerminal | Symbol[]>>;
export declare class SimpleGrammar implements IGrammar {
protected prodIdCounter: number;
protected non_terminals: NonTerminal[];
protected productions: Production[];
protected prodMap: Map<number, Production>;
constructor(rawGrammar: RawSimpleGrammar);
protected beforeConstruct(rawGrammar: RawSimpleGrammar): void;
protected construct(rawGrammar: RawSimpleGrammar): void;
protected afterConstruct(): void;
toString(): string;
NTS(): NonTerminal[];
Prods(): Production[];
startNT(): NonTerminal;
}
export declare type RawProduction = {
action?: ASTMaker;
body: Symbol[];
};
export declare type TerminalTrait = {
prec: number;
leftAssoc: boolean;
};
export declare type TraitsTable = Map<Terminal, TerminalTrait>;
export declare type RawActionGrammar = Array<Array<NonTerminal | RawProduction | ASTMaker>>;
export declare class ActionGrammar implements IGrammar {
protected prodIdCounter: number;
protected nonTerminals: NonTerminal[];
protected productions: Production[];
protected productionsMap: Map<number, Production>;
protected traits: TraitsTable;
constructor(rawGrammar: RawActionGrammar, traits?: TraitsTable);
protected beforeConstruct(rawGrammar: RawActionGrammar): void;
protected construct(rawGrammar: RawActionGrammar): void;
private determineProdTrait;
protected afterConstruct(): void;
toString(): string;
NTS(): NonTerminal[];
Prods(): Production[];
startNT(): NonTerminal;
}
export declare class GrammarError extends Error {
}