Parser 2.0 (Major Delezer) #52

Merged
defunkt merged 35 commits from parser2 into main 2025-12-08 16:35:34 +00:00
2 changed files with 15 additions and 2 deletions
Showing only changes of commit f160093c4d - Show all commits

View File

@ -100,7 +100,7 @@ export function parseFile(path: string, globals?: Record<string, any>): SyntaxNo
return parseCode(code, globals)
}
export function parseCode(code: string, globals?: Record<string, any>): SyntaxNode {
export function parseCode(code: string, globals?: Record<string, any>): Tree {
const oldGlobals = [...parserGlobals]
const globalNames = [...Object.keys(prelude), ...(globals ? Object.keys(globals) : [])]
@ -108,5 +108,5 @@ export function parseCode(code: string, globals?: Record<string, any>): SyntaxNo
const result = parse(code)
setParserGlobals(oldGlobals)
return result
return new Tree(result)
}

View File

@ -114,6 +114,19 @@ export const operators: Record<string, any> = {
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