silverbullet/common/expression_parser.ts

13 lines
606 B
TypeScript
Raw Permalink Normal View History

import type { QueryExpression } from "@silverbulletmd/silverbullet/types";
import { parseTreeToAST } from "@silverbulletmd/silverbullet/lib/tree";
import { expressionLanguage } from "$common/template/template_parser.ts";
import { expressionToKvQueryExpression } from "@silverbulletmd/silverbullet/lib/parse_query";
import { lezerToParseTree } from "$common/markdown_parser/parse_tree.ts";
export function parseExpression(s: string): QueryExpression {
2024-08-02 23:14:40 +08:00
const ast = parseTreeToAST(
lezerToParseTree(s, expressionLanguage.parser.parse(s).topNode),
);
return expressionToKvQueryExpression(ast[1]);
}