ima-parse
Version:
Easy Simple Parser, that only requires a Grammar JSON to output an AST.
30 lines (29 loc) • 1.1 kB
TypeScript
import { Position } from "../helpers/helpers";
import { RuleParser } from "../parser/RuleParser";
import { GrammarRule, Grammar } from "../parser/grammarTypes";
export type BuildRuleFn = (parsedRule: RuleParser, ruleBuilders: RuleBuilders) => RuleContentTree;
export type RuleBuilders = Map<GrammarRule, BuildRuleFn>;
type ValueInfo = {
type: string;
value: any;
position: Position;
};
export type RuleContentTree = {
$type: string;
$position: Position;
$keywords?: ValueInfo[];
} & {
[key: string]: ValueInfo;
};
/**
* Fill a tree, that adheres to the before created types (`getTypesAndBuildersFromGrammar()`), with the read data that's in a RuleParser.
*/
export declare function buildContentTree<T = RuleContentTree>(ruleBuilders: RuleBuilders, topLevelParser: RuleParser): T;
/**
* Read the `Grammar` and generate types that parsed data will adhere to. The rulebuilders should be used to actually build the content tree
*/
export declare function getTypesAndBuildersFromGrammar(grammar: Grammar): {
types: string[];
ruleBuilders: RuleBuilders;
};
export {};