Skip to content

Commit 01d428d

Browse files
committed
Add docs on highlighting
1 parent 7357885 commit 01d428d

File tree

4 files changed

+82
-13
lines changed

4 files changed

+82
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Elixir grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
66

77
## Development
88

9-
See [the docs](./docs.md) for development notes.
9+
See [the docs](./docs/index.md) for more details.

docs/highlighting.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Syntax highlighting
2+
3+
For detailed introduction see the official guide on [Syntax highlighting](https://tree-sitter.github.io/tree-sitter/syntax-highlighting).
4+
5+
Briefly speaking, Tree-sitter uses the rules in `queries/highlights.scm` to annotate nodes
6+
with specific tokens, then it maps those tokens to formatting style according to user-defined
7+
theme.
8+
9+
To test highlighting using the CLI, you need to create local configuration.
10+
11+
```shell
12+
# Create the config file
13+
npx tree-sitter init-config
14+
```
15+
16+
The above command should print out the config location, so that you can further configure it.
17+
Open the file and modify `"parser-directories"` to include the parent directory of `tree-sitter-elixir`.
18+
Also, you can optionally customize the theme, here's a tiny subset of the One Dark theme:
19+
20+
```json
21+
{
22+
"number": {
23+
"color": "#61afef",
24+
"bold": true
25+
},
26+
"string": "#98c379",
27+
"string.escape": "#56b6c2",
28+
"string.special": "#61afef",
29+
"string.regexp": "#e06c75",
30+
"type": "#e06c75",
31+
"comment": {
32+
"color": "#5c6370",
33+
"italic": true
34+
},
35+
"punctuation": "#abb2bf",
36+
"punctuation.special": "#be5046",
37+
"operator": {
38+
"color": "#d19a66",
39+
"bold": true
40+
},
41+
"variable": "#abb2bf",
42+
"function": "#61afef",
43+
"constant": "#61afef",
44+
"constant.builtin": {
45+
"color": "#e06c75",
46+
"bold": true
47+
},
48+
"keyword": "#c678dd",
49+
"attribute": "#e06c75",
50+
"embedded": null
51+
}
52+
```
53+
54+
With this setup you can test highlighting on files using the Tree-sitter CLI.
55+
56+
```shell
57+
npx tree-sitter highlight tmp/test.ex
58+
59+
npx tree-sitter highlight test/highlight/**/*.ex
60+
```

docs/index.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Development notes
2+
3+
This documentation covers rationale behind some of the design and implementation decisions,
4+
as well as basic Tree-sitter tips that are relevant.
5+
6+
## Pages
7+
8+
* [Parser](./parser.md)
9+
* [Highlighting](./highlighting.md)
10+
11+
## Acknowledgements
12+
13+
While this parser is written from scratch, there were previous efforts that made
14+
for a helpful reference:
15+
16+
* [tree-sitter-elixir](https://github.com/ananthakumaran/tree-sitter-elixir) developed
17+
by [@ananthakumaran](https://github.com/ananthakumaran)
18+
* [tree-sitter-elixir](https://github.com/wingyplus/tree-sitter-elixir) developed
19+
by [@wingyplus](https://github.com/wingyplus) and [@Tuxified](https://github.com/Tuxified)

docs.md renamed to docs/parser.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
# Development notes
2-
3-
## Acknowledgements
4-
5-
While this parser is written from scratch, there were previous efforts that made
6-
for a helpful reference:
7-
8-
* [tree-sitter-elixir](https://github.com/ananthakumaran/tree-sitter-elixir) developed
9-
by [@ananthakumaran](https://github.com/ananthakumaran)
10-
* [tree-sitter-elixir](https://github.com/wingyplus/tree-sitter-elixir) developed
11-
by [@wingyplus](https://github.com/wingyplus) and [@Tuxified](https://github.com/Tuxified)
1+
# Parser
122

133
## The AST
144

@@ -39,7 +29,7 @@ like, have a look at the tests in `test/corpus/`.
3929
4030
## Getting started with Tree-sitter
4131
42-
For official notes see the official guide on [Creating parsers](https://tree-sitter.github.io/tree-sitter/creating-parsers).
32+
For detailed introduction see the official guide on [Creating parsers](https://tree-sitter.github.io/tree-sitter/creating-parsers).
4333
4434
Essentially, we define relevant language rules in `grammar.js`, based on which
4535
Tree-sitter generates parser code (under `src/`). In some cases, we want to write

0 commit comments

Comments
 (0)