match lezer API
This commit is contained in:
parent
6da00dd3c8
commit
ccf8f41544
|
|
@ -100,7 +100,7 @@ export function parseFile(path: string, globals?: Record<string, any>): SyntaxNo
|
||||||
return parseCode(code, globals)
|
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 oldGlobals = [...parserGlobals]
|
||||||
const globalNames = [...Object.keys(prelude), ...(globals ? Object.keys(globals) : [])]
|
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)
|
const result = parse(code)
|
||||||
setParserGlobals(oldGlobals)
|
setParserGlobals(oldGlobals)
|
||||||
|
|
||||||
return result
|
return new Tree(result)
|
||||||
}
|
}
|
||||||
|
|
@ -114,6 +114,19 @@ export const operators: Record<string, any> = {
|
||||||
|
|
||||||
export class Tree {
|
export class Tree {
|
||||||
constructor(public topNode: SyntaxNode) { }
|
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
|
// TODO: TEMPORARY SHIM
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user