import * as TSU from "@panyam/tsutils"; import * as TLEX from "tlex"; import { Sym, Grammar, Rule } from "./grammar"; import { PTNode, SimpleParser as ParserBase, BeforeAddingChildCallback, RuleReductionCallback, NextTokenCallback } from "./parser"; type Nullable = TSU.Nullable; type NumMap = TSU.NumMap; type StringMap = TSU.StringMap; export declare enum LRActionType { ACCEPT = 0, SHIFT = 1, REDUCE = 2, GOTO = 3 } export declare class LRAction { tag: LRActionType; gotoState: Nullable; rule: Nullable; toString(): string; equals(another: LRAction): boolean; static Shift(goto: number): LRAction; static Reduce(rule: Rule): LRAction; static Goto(gotoState: number): LRAction; static Accept(): LRAction; } export declare class ParseTable { readonly grammar: Grammar; conflictActions: NumMap>; actions: NumMap>; constructor(grammar: Grammar); get hasConflicts(): boolean; getActions(stateId: number, next: Sym, ensure?: boolean): LRAction[]; addAction(stateId: number, next: Sym, action: LRAction): this; get debugValue(): any; } export declare class ParseStack { readonly stateStack: number[]; readonly nodeStack: PTNode[]; push(state: number, node: PTNode): void; top(nth?: number): [number, PTNode]; pop(): [number, PTNode]; popN(n?: number): void; get isEmpty(): boolean; } export type ActionResolverCallback = (actions: LRAction[], stack: ParseStack, tokenbuffer: TLEX.TokenBuffer) => LRAction; export type RuleActionHandler = (rule: Rule, parent: PTNode, ...children: PTNode[]) => any; export type TokenErrorCallback = (err: TLEX.TokenizerError, input: TLEX.Tape) => boolean; export interface ParserContext { buildParseTree?: boolean; copySingleChild?: boolean; ruleHandlers: TSU.StringMap; beforeAddingChildNode?: BeforeAddingChildCallback; onReduction?: RuleReductionCallback; onNextToken?: NextTokenCallback; actionResolver?: ActionResolverCallback; onTokenError?: TokenErrorCallback; tokenizerContext: any; } export declare class Parser extends ParserBase { readonly parseTable: ParseTable; constructor(parseTable: ParseTable, config?: any); get grammar(): Grammar; protected parseInput(input: TLEX.Tape, context?: ParserContext): Nullable; } export {};