UNPKG

parseit.js

Version:

Customizable parsing library for converting a list of tokens into an AST tree

42 lines (41 loc) 1.44 kB
import { ASTNodeConstructor } from "../classes/ASTNode"; export declare type GrammarRuleContentItem = GrammarAtom | GrammarBinaryLoop | GrammarBlockLoop[] | GrammarEither; export declare type GrammarRuleContent = GrammarRuleContentItem[]; export declare enum GrammarAtomType { RULE = 0, TOKEN = 1 } export declare enum GrammarRuleSpecialMatch { PASS = 0, FUNC = 1 } /** The grammar rule variation */ export default class GrammarRule { name: string; content: GrammarRuleContent; match: ASTNodeConstructor | GrammarRuleSpecialMatch; func?: Function; ignored?: GrammarAtom[]; preventRollback: boolean; constructor(name: string, content: GrammarRuleContent, match: ASTNodeConstructor | GrammarRuleSpecialMatch, func?: Function, ignored?: GrammarAtom[], preventRollback?: boolean); } /** A single grammar rule variation object. Can be a token or a reference to another rule */ export declare class GrammarAtom { name: string; value: any; type: GrammarAtomType; skip: boolean; constructor(name: string, type: GrammarAtomType, value?: any, skip?: boolean); } /** Binary loop grammar item */ export declare class GrammarBinaryLoop { content: GrammarRuleContent; } /** Block loop grammar item */ export declare class GrammarBlockLoop { content: GrammarRuleContent; } /** Either selector grammar item */ export declare class GrammarEither { variants: GrammarRuleContent; }