on master help sign in
Improved yuck highlighting (and parser), and introduced a tag.builtin scope (#6242)
98415f2Philipp Mildenberger
book/src/themes.md+1
@@ -215,6 +215,7 @@ We use a similar set of scopes as
215 - `special` (preprocessor in C)
215 - `special` (preprocessor in C)
216
216
217- `tag` - Tags (e.g. `<body>` in HTML)
217- `tag` - Tags (e.g. `<body>` in HTML)
218+ - `builtin`
218
219
219- `namespace`
220- `namespace`
220
221
languages.toml+1−1
@@ -2206,7 +2206,7 @@ indent = { tab-width = 2, unit = " " }
2206
2206
2207[[grammar]]
2207[[grammar]]
2208name = "yuck"
2208name = "yuck"
2209−source = { git = "https://github.com/Philipp-M/tree-sitter-yuck", rev = "9e97da5773f82123a8c8cccf8f7e795d140ed7d1" }
2209+source = { git = "https://github.com/Philipp-M/tree-sitter-yuck", rev = "e3d91a3c65decdea467adebe4127b8366fa47919" }
2210
2210
2211[[language]]
2211[[language]]
2212name = "prql"
2212name = "prql"
runtime/queries/yuck/highlights.scm+88−47
@@ -1,66 +1,107 @@
1+; Errors
2+
1(ERROR) @error
3(ERROR) @error
2
4
3−(line_comment) @comment
5+; Comments
4
6
5−; keywords and symbols
7+(comment) @comment
6
8
7−(keyword) @keyword
9+; Operators
8−(symbol) @tag
9
10
10−; literals
11+[
12+ "+"
13+ "-"
14+ "*"
15+ "/"
16+ "%"
17+ "||"
18+ "&&"
19+ "=="
20+ "!="
21+ "=~"
22+ ">"
23+ "<"
24+ ">="
25+ "<="
26+ "!"
27+ "?."
28+ "?:"
29+] @operator
11
30
12−(bool_literal) @constant.builtin.boolean
31+(ternary_expression
13−(num_literal) @constant.numeric
32+ ["?" ":"] @operator)
14
33
15−; strings
34+; Punctuation
16−(string_interpolation
35+
17− (string_interpolation_start) @punctuation.special
36+[ ":" "." "," ] @punctuation.delimiter
18− (string_interpolation_end) @punctuation.special)
37+
38+[ "{" "}" "[" "]" "(" ")" ] @punctuation.bracket
39+
40+; Literals
41+
42+(number (float)) @constant.numeric.float
43+
44+(number (integer)) @constant.numeric.integer
45+
46+(boolean) @constant.builtin.boolean
47+
48+; Strings
19
49
20(escape_sequence) @constant.character.escape
50(escape_sequence) @constant.character.escape
21
51
22−(string
52+(string_interpolation
23− [
53+ "${" @punctuation.special
24− (unescaped_single_quote_string_fragment)
54+ "}" @punctuation.special)
25− (unescaped_double_quote_string_fragment)
26− (unescaped_backtick_string_fragment)
27− "\""
28− "'"
29− "`"
30− ]) @string
31
55
32−; operators and general punctuation
56+[ (string_fragment) "\"" "'" "`" ] @string
33
57
34−(unary_expression
58+; Attributes & Fields
35− operator: _ @operator)
36
59
37−(binary_expression
60+(keyword) @attribute
38− operator: _ @operator)
39
61
40−(ternary_expression
62+; Functions
41− operator: _ @operator)
42
63
43−[
64+(function_call
44− ":"
65+ name: (ident) @function)
45− "."
46− ","
47−] @punctuation.delimiter
48
66
49−[
67+; Variables
50− "("
51− ")"
52− "["
53− "]"
54− "{"
55− "}"
56−] @punctuation.bracket
57−[
58− ":"
59− "."
60− ","
61−] @punctuation.delimiter
62
68
63−; Rest (general identifiers that are not yet catched)
69+(ident) @variable
70+
71+(array
72+ (symbol) @variable)
73+
74+; Builtin widgets
75+
76+(list .
77+ ((symbol) @tag.builtin
78+ (#match? @tag.builtin "^(box|button|calendar|centerbox|checkbox|circular-progress|color-button|color-chooser|combo-box-text|eventbox|expander|graph|image|input|label|literal|overlay|progress|revealer|scale|scroll|transform)$")))
79+
80+; Keywords
81+
82+; I think there's a bug in tree-sitter the anchor doesn't seem to be working, see
83+; https://github.com/tree-sitter/tree-sitter/pull/2107
84+(list .
85+ ((symbol) @keyword
86+ (#match? @keyword "^(defwindow|defwidget|defvar|defpoll|deflisten|geometry|children|struts)$")))
87+
88+(list .
89+ ((symbol) @keyword.control.import
90+ (#eq? @keyword.control.import "include")))
91+
92+; Loop
93+
94+(loop_widget . "for" @keyword.control.repeat . (symbol) @variable . "in" @keyword.operator . (symbol) @variable)
95+
96+(loop_widget . "for" @keyword.control.repeat . (symbol) @variable . "in" @keyword.operator)
97+
98+; Tags
99+
100+; TODO apply to every symbol in list? I think it should probably only be applied to the first child of the list
101+(list
102+ (symbol) @tag)
103+
104+; Other stuff that has not been catched by the previous queries yet
64
105
65−(index) @variable
66(ident) @variable
106(ident) @variable
107+(index) @variable
runtime/queries/yuck/injections.scm+1−1
@@ -1,2 +1,2 @@
1−((line_comment) @injection.content
1+((comment) @injection.content
2 (#set! injection.language "comment"))
2 (#set! injection.language "comment"))