From ccf8f41544aba924b6cd52f003442058ba95cdc2 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath <2+defunkt@users.noreply.github.com> Date: Tue, 25 Nov 2025 16:57:18 -0800 Subject: [PATCH] match lezer API --- src/index.ts | 4 ++-- src/parser/node.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index f77f99b..8de5373 100644 --- a/src/index.ts +++ b/src/index.ts @@ -100,7 +100,7 @@ export function parseFile(path: string, globals?: Record): SyntaxNo return parseCode(code, globals) } -export function parseCode(code: string, globals?: Record): SyntaxNode { +export function parseCode(code: string, globals?: Record): Tree { const oldGlobals = [...parserGlobals] const globalNames = [...Object.keys(prelude), ...(globals ? Object.keys(globals) : [])] @@ -108,5 +108,5 @@ export function parseCode(code: string, globals?: Record): SyntaxNo const result = parse(code) setParserGlobals(oldGlobals) - return result + return new Tree(result) } \ No newline at end of file diff --git a/src/parser/node.ts b/src/parser/node.ts index 48f4956..67838ef 100644 --- a/src/parser/node.ts +++ b/src/parser/node.ts @@ -114,6 +114,19 @@ export const operators: Record = { export class Tree { constructor(public topNode: SyntaxNode) { } + + get length(): number { + return this.topNode.to + } + + cursor() { + return { + type: this.topNode.type, + from: this.topNode.from, + to: this.topNode.to, + node: this.topNode, + } + } } // TODO: TEMPORARY SHIM