parseit.js
Version:
Customizable parsing library for converting a list of tokens into an AST tree
30 lines (29 loc) • 928 B
TypeScript
import Token from "../classes/Token";
import Grammar from "../grammar/grammar";
import { GrammarRuleContent } from "../grammar/rule";
export declare type RuleVariationContentStackItem = {
content: GrammarRuleContent;
type: ContentStackType;
index: number;
};
export declare type RuleVariationContentStack = RuleVariationContentStackItem[];
export declare enum ContentStackType {
RULE = 0,
BINARY = 1,
BLOCK = 2
}
export default class Parser {
tokens: Token[];
index: number;
grammar: Grammar;
/** The main parser object. Takes the grammar object as a constructor argument */
constructor(grammar: Grammar);
/** Takes an array of tokens and constructs an AST tree based on the grammar rules */
parse(tokens: Token[]): any;
private evaluateRule;
private evaluateOnePiece;
private advance;
private rollback;
private stackLayer;
private get currentTok();
}