You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/design.md
+55-21Lines changed: 55 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -32,29 +32,43 @@ In short:
32
32
33
33
## tree-sitter-clojure
34
34
35
-
Clojure-ts-mode uses the tree-sitter-clojure grammar, which can be found at <https://github.com/sogaiu/tree-sitter-clojure>
36
-
The clojure-ts-mode grammar provides very basic, low level nodes that try to match Clojure's very light syntax.
35
+
`clojure-ts-mode` uses the experimental version tree-sitter-clojure grammar, which
36
+
can be found at
37
+
<https://github.com/sogaiu/tree-sitter-clojure/tree/unstable-20250526>. The
38
+
`clojure-ts-mode` grammar provides very basic, low level nodes that try to match
39
+
Clojure's very light syntax.
37
40
38
41
There are nodes to represent:
39
42
40
-
- Symbols (sym_lit)
41
-
- Contain (sym_ns) and (sym_name) nodes
42
-
- Keywords (kwd_lit)
43
-
- Contain (kwd_ns) and (kw_name) nodes
44
-
- Strings (str_lit)
45
-
- Chars (char_lit)
46
-
- Nil (nil_lit)
47
-
- Booleans (bool_lit)
48
-
- Numbers (num_lit)
49
-
- Comments (comment, dis_expr)
50
-
- dis_expr is the `#_` discard expression
51
-
- Lists (list_list)
52
-
- Vectors (vec_lit)
53
-
- Maps (map_lit)
54
-
- Sets (set_lit)
55
-
56
-
There are also nodes to represent metadata, which appear on `meta:` child fields of the nodes the metadata is defined on.
57
-
For example a simple vector with metadata defined on it like so
43
+
- Symbols `(sym_lit)`
44
+
- Contain `(sym_ns)` and `(sym_name)` nodes
45
+
- Keywords `(kwd_lit)`
46
+
- Contain `(kwd_ns)` and `(kw_name)` nodes
47
+
- Strings `(str_lit)`
48
+
- Contains `(str_content)` node
49
+
- Chars `(char_lit)`
50
+
- Nil `(nil_lit)`
51
+
- Booleans `(bool_lit)`
52
+
- Numbers `(num_lit)`
53
+
- Comments `(comment, dis_expr)`
54
+
-`dis_expr` is the `#_` discard expression
55
+
- Lists `(list_list)`
56
+
- Vectors `(vec_lit)`
57
+
- Maps `(map_lit)`
58
+
- Sets `(set_lit)`
59
+
- Metadata nodes `(meta_lit)`
60
+
- Regex content `(regex_content)`
61
+
- Function literals `(anon_fn_lit)`
62
+
63
+
The best place to learn more about the tree-sitter-clojure grammar is to read
64
+
the [grammar.js file from the tree-sitter-clojure repository](https://github.com/sogaiu/tree-sitter-clojure/blob/master/grammar.js"grammar.js").
65
+
66
+
### Difference between stable grammar and experimental
67
+
68
+
#### Standalone metadata nodes
69
+
70
+
Metadata nodes in stable grammar appear as child nodes of the nodes the metadata
71
+
is defined on. For example a simple vector with metadata defined on it like so:
58
72
59
73
```clojure
60
74
^:has-metadata [1]
@@ -69,7 +83,27 @@ will produce a parse tree like so
69
83
value: (num_lit))
70
84
```
71
85
72
-
The best place to learn more about the tree-sitter-clojure grammar is to read the [grammar.js file from the tree-sitter-clojure repository](https://github.com/sogaiu/tree-sitter-clojure/blob/master/grammar.js"grammar.js").
86
+
Although it's somewhat closer to hoe Clojure treats metadata itself, in the
87
+
context of a text editor it creates some problems, which were discussed [here](https://github.com/sogaiu/tree-sitter-clojure/issues/65). To
88
+
name a few:
89
+
-`forward-sexp` command would skip both, metadata and the node it's attached
90
+
to. Called from an opening paren it would signal an error "No more sexp to
91
+
move across".
92
+
-`kill-sexp` command would kill both, metadata and the node it's attached to.
93
+
-`backward-up-list` called from the inside of a list with metadata would move
94
+
point to the beginning of metadata node.
95
+
- Internally we had to introduce some workarounds to skip metadata nodes or
96
+
figure out where the actual node starts.
97
+
98
+
#### Special nodes for string content and regex content
99
+
100
+
To parse the content of certain strings with a separate grammar, it is necessary
101
+
to extract the string's content, excluding its opening and closing quotes. To
102
+
achieve this, Emacs 31 allows specifying offsets for `treesit-range-settings`.
103
+
However, in Emacs 30.1, this feature is broken due to bug [#77848](https://debbugs.gnu.org/cgi/bugreport.cgi?bug=77848) (a fix is
104
+
anticipated in Emacs 30.2). The presence of `str_content` and `regex_content` nodes
105
+
allows us to support this feature across all Emacs versions without relying on
0 commit comments