lezer-ludus/test.js

33 lines
596 B
JavaScript
Raw Normal View History

2023-11-26 18:02:33 +00:00
import {parser} from "./parser.js"
2023-11-26 22:28:15 +00:00
const source = `
if foo
2023-12-15 22:20:48 +00:00
then bar else asdf
2023-11-26 22:28:15 +00:00
`
2023-11-26 18:32:25 +00:00
const parse = (source) => parser.parse(source.concat("\n"))
2023-12-15 22:20:48 +00:00
const tree = parse(source)
const cursor = tree.cursor()
const report = (out) => {
console.log(out);
return true;
}
const visit = (node) => {
switch (node.type.name) {
case "Script": return report("Starting Script");
case "If": return report("Starting If");
case "Word": return report(node.)
}
}
cursor.iterate(
(node) => (console.log("Entering", node.type.name), true),
(node) => (console.log("Leaving", node.type.name))
)