Parser 2.0 (Major Delezer) #52
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user