42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { parser } from '../../src/parser/shrimp'
|
|
import { setGlobals } from '../../src/parser/tokenizer'
|
|
import { PRELUDE_NAMES } from '../server/src/prelude-names'
|
|
|
|
// Set globals for DotGet detection
|
|
setGlobals(PRELUDE_NAMES as unknown as string[])
|
|
|
|
// Test cases - does incomplete DotGet parse correctly?
|
|
const testCases = [
|
|
'dict.',
|
|
'dict.g',
|
|
'dict.get',
|
|
'$.',
|
|
'$.e',
|
|
'$.env',
|
|
]
|
|
|
|
for (const code of testCases) {
|
|
console.log(`\nTesting: "${code}"`)
|
|
const tree = parser.parse(code)
|
|
const cursor = tree.cursor()
|
|
|
|
// Print the parse tree
|
|
const printTree = (depth = 0) => {
|
|
const indent = ' '.repeat(depth)
|
|
console.log(`${indent}${cursor.name} [${cursor.from}-${cursor.to}]`)
|
|
|
|
if (cursor.firstChild()) {
|
|
do {
|
|
printTree(depth + 1)
|
|
} while (cursor.nextSibling())
|
|
cursor.parent()
|
|
}
|
|
}
|
|
|
|
printTree()
|
|
|
|
// Check at cursor position (end of string)
|
|
const node = tree.resolveInner(code.length, -1)
|
|
console.log(`Node at end: ${node.name} (type: ${node.type.id})`)
|
|
}
|