Skip to content

Commit b78de56

Browse files
committed
doc: Explain the principles of tree-sitter-langs's hl query patterns
[skip ci]
1 parent 1a01f40 commit b78de56

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

doc/emacs-tree-sitter.org

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ If, for some reason, you cannot update, the older binaries can be downloaded fro
191191
:EXPORT_TITLE: Syntax Highlighting
192192
:END:
193193

194-
Syntax highlighting is provided by the minor mode ~tree-sitter-hl-mode~. It overrides the regex-based highlighting provided by ~font-lock-mode~, using the syntax tree provided by ~tree-sitter-mode~. It is based on *tree queries*, a system for pattern-matching on Tree-sitter's syntax trees.
194+
Syntax highlighting is provided by the minor mode ~tree-sitter-hl-mode~. It overrides the regex-based highlighting provided by ~font-lock-mode~, using the syntax tree provided by ~tree-sitter-mode~. It is based on [[* Queries][*tree queries*]], a system for pattern-matching on Tree-sitter's syntax trees.
195195

196196
It can be toggled in a buffer by the command ~tree-sitter-hl-mode~, or enabled through major mode hooks:
197197
#+begin_src emacs-lisp
@@ -203,25 +203,22 @@ To enable it whenever possible (assuming the language major modes were already i
203203
(global-tree-sitter-mode)
204204
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)
205205
#+end_src
206-
207-
The package ~tree-sitter-langs~ provides syntax highlighting [[https://github.com/emacs-tree-sitter/tree-sitter-langs/tree/master/queries][queries]] for some languages:
208-
- C
209-
- C++
210-
- *CSS*
211-
- Go
212-
- HTML
213-
- Java
214-
- *JavaScript*
215-
- PHP
216-
- *Python*
217-
- Ruby
218-
- *Rust*
219-
- *TypeScript*
206+
*** tree-sitter-langs
207+
The package ~tree-sitter-langs~ provides syntax highlighting [[https://github.com/emacs-tree-sitter/tree-sitter-langs/tree/master/queries][queries]] for some languages.
208+
209+
Most of them are *intentionally different* from those from upstream repositories, which are more geared towards /GitHub's use cases/. We try to be more consistent with /Emacs's existing conventions/. The general principles are:
210+
- Definitions and uses should be differentiated:
211+
+ ~@function~ vs. ~@function.call~.
212+
+ ~@method~ vs. ~@method.call~.
213+
+ ~@type.parameter~ vs. ~@type.argument~.
214+
- ~@variable~ and ~@variable.parameter~ should be applied only to declarations/definitions/bindings/mutations (/writes/), not usage (/reads/).
215+
- Special faces should have high priority (placed earlier in the pattern list): ~@function.macro~, ~@type.builtin~, ~@variable.special~.
216+
- Patterns whose internals may be highlighted should have low priority (placed towards the end). Example: strings with interpolation.
220217

221218
{{% notice info %}}
222-
Most of the [[https://github.com/emacs-tree-sitter/tree-sitter-langs/tree/master/queries][highlighting queries]] in the bundle are very basic, as they are copies of those included in the [[https://github.com/tree-sitter][grammar repositories]]. Queries for languages written in bold have received additional work to leverage more of the querying system's expressiveness.
219+
For some languages, the highlighting patterns are similar to those from upstream [[https://github.com/tree-sitter][grammar repositories]], instead of extensively following the above principles. They should be considered WIP.
223220

224-
Contributions to highlighting queries are welcome.
221+
Contributions to improve them are welcome.
225222
{{% /notice %}}
226223

227224
** Queries

0 commit comments

Comments
 (0)