Skip to content

Commit bd07db4

Browse files
committed
add highlighting rules
1 parent c898a59 commit bd07db4

File tree

3 files changed

+89
-3
lines changed

3 files changed

+89
-3
lines changed

bindings/rust/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! ```
77
//! let code = "";
88
//! let mut parser = tree_sitter::Parser::new();
9-
//! parser.set_language(tree_sitter_go_template::language()).expect("Error loading YOUR_LANGUAGE_NAME grammar");
9+
//! parser.set_language(tree_sitter_go_template::language()).expect("Error loading go-template grammar");
1010
//! let tree = parser.parse(code, None).unwrap();
1111
//! ```
1212
//!

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
"scripts": {
2020
"build": "tree-sitter generate && node-gyp build",
2121
"test": "tree-sitter test",
22-
"parse": "tree-sitter parse"
23-
}
22+
"parse": "tree-sitter parse",
23+
"highlight": "tree-sitter highlight"
24+
},
25+
"tree-sitter": [
26+
{
27+
"scope": "source.gotexttmpl",
28+
"file-types": [
29+
"gotexttmpl",
30+
"gohtmltmpl",
31+
"gotmpl"
32+
]
33+
}
34+
]
2435
}

queries/highlights.scm

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
; Identifiers
2+
3+
[
4+
(field)
5+
(field_identifier)
6+
] @property
7+
8+
(variable) @variable
9+
10+
; Function calls
11+
12+
(function_call
13+
function: (identifier) @function)
14+
15+
(method_call
16+
method: (selector_expression
17+
field: (field_identifier) @function))
18+
19+
; Operators
20+
21+
"|" @operator
22+
":=" @operator
23+
24+
; Builtin functions
25+
26+
((identifier) @function.builtin
27+
(#match? @function.builtin "^(and|call|html|index|slice|js|len|not|or|print|printf|println|urlquery|eq|ne|lt|ge|gt|ge)$"))
28+
29+
; Delimiters
30+
31+
"." @punctuation.delimiter
32+
"," @punctuation.delimiter
33+
34+
"{{" @punctuation.bracket
35+
"}}" @punctuation.bracket
36+
"{{-" @punctuation.bracket
37+
"-}}" @punctuation.bracket
38+
")" @punctuation.bracket
39+
"(" @punctuation.bracket
40+
41+
; Keywords
42+
43+
"else" @keyword
44+
"if" @keyword
45+
"range" @keyword
46+
"with" @keyword
47+
"end" @keyword
48+
"template" @keyword
49+
"define" @keyword
50+
"block" @keyword
51+
52+
; Literals
53+
54+
[
55+
(interpreted_string_literal)
56+
(raw_string_literal)
57+
(rune_literal)
58+
] @string
59+
60+
(escape_sequence) @string.special
61+
62+
[
63+
(int_literal)
64+
(float_literal)
65+
(imaginary_literal)
66+
] @number
67+
68+
[
69+
(true)
70+
(false)
71+
(nil)
72+
] @constant.builtin
73+
74+
(comment) @comment
75+
(ERROR) @error

0 commit comments

Comments
 (0)