@1771technologies/lytenyte-pro
Version:
Blazingly fast headless React data grid with 100s of features.
27 lines (26 loc) • 922 B
JavaScript
import { current } from "./parser-context.js";
import { tokenize } from "../lexer/tokenize/tokenize.js";
import { ExpressionError } from "../errors/expression-error.js";
import { parseExpression } from "./parse-expression.js";
const MAX_PARSE_DEPTH = 32;
export function parse(source, depth = 0, plugins) {
if (depth > MAX_PARSE_DEPTH) {
throw new ExpressionError("Maximum template nesting depth exceeded", {
source,
start: 0,
end: source.length,
});
}
const tokens = tokenize(source, plugins);
const ctx = { tokens, pos: 0, source, depth, plugins };
const result = parseExpression(ctx, 0);
if (current(ctx).type !== "EOF") {
const tok = current(ctx);
throw new ExpressionError(`Unexpected token "${tok.value}"`, {
source,
start: tok.start,
end: tok.end,
});
}
return result;
}