Skip to content

Commit 891c3be

Browse files
committed
Initial query experiments
1 parent e4a3b9c commit 891c3be

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

.vscode/tasks.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
"reveal": "never"
4242
},
4343
"group": "build"
44+
},
45+
{
46+
"label": "Parse quarry",
47+
"type": "shell",
48+
"command": "npx tree-sitter query scopeTypes.scm ts-test.ts",
49+
"presentation": {}
4450
}
4551
]
4652
}

queries/typescript/scopeTypes.scm

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
(object) @map
2+
3+
(arrow_function) @anonymousFunction
4+
(function) @anonymousFunction
5+
6+
; We could also have used an alternation here, but the above style is clean and
7+
; seems to be more commonly used.
8+
; [
9+
; (arrow_function)
10+
; (function)
11+
; ] @anonymousFunction
12+
13+
; The following doesn't work because we can't have a `(` before the field name (`key`)
14+
; (
15+
; (object
16+
; (pair
17+
; (key: (_) @key
18+
; .
19+
; ":") @key.removalRange
20+
; ) @key.searchScope
21+
; ) @key.iterationScope
22+
; )
23+
24+
; As a workaround, we could allow defining the end of an annotation
25+
(
26+
(object
27+
(pair
28+
key: (_) @key
29+
.
30+
":" @key.removalRange.end
31+
) @key.searchScope
32+
) @key.iterationScope
33+
)
34+
35+
; We could instead tag the delimiter itself. Gives us a bit more information,
36+
; so maybe that's better?
37+
(
38+
(object
39+
(pair
40+
key: (_) @key
41+
.
42+
":" @key.delimiter.trailing)
43+
@key.searchScope)
44+
@key.iterationScope)
45+
46+
; We could also try setting an attribute. This approach is likely how we'd
47+
; handle comma-separated lists, because they'd be a bit painful to define as
48+
; parse tree patterns
49+
(
50+
(object
51+
(pair
52+
key: (_) @key
53+
(#set! "delimiter" ":")
54+
)
55+
@key.searchScope)
56+
@key.iterationScope)

0 commit comments

Comments
 (0)