-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsandbox.js
38 lines (33 loc) · 1.02 KB
/
sandbox.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Sandbox
// (pretty-print tree from given text)
const text = `
(defn foo
"hello, this is a docstring"
[a b]
(let [sum (+ a b)
prod (* a b)]
{:sum sum
:prod prod}))
`;
const { partialSexp, fullSexp, printSexp } = require("highlight-tree-sitter");
const Parser = require("tree-sitter");
const Clojure = require("./index.js");
const parser = new Parser();
parser.setLanguage(Clojure);
const tree = parser.parse(text);
const partial = partialSexp(tree);
const full = fullSexp(text, tree);
console.log(`
======================================================================
Parsing text:
======================================================================
${text}
======================================================================
Partial Tree:
======================================================================
${printSexp(partial)}
======================================================================
Full Tree:
======================================================================
${printSexp(full)}
`);