on master help sign in
Improved yuck highlighting (and parser), and introduced a tag.builtin scope (#6242)
commit98415f288ffa043520b0c85bc4464dc44b85f948 authorPhilipp Mildenberger <philipp@mildenberger.me> dateFri 10 Mar 2023, 17:32 (4 years ago) parentd63e570
4 files changed+91−49
book/src/themes.md+1 languages.toml+1−1 runtime/queries/yuck/highlights.scm+88−47 runtime/queries/yuck/injections.scm+1−1
book/src/themes.md+1
@@ -215,6 +215,7 @@ We use a similar set of scopes as
215215 - `special` (preprocessor in C)
216216
217217- `tag` - Tags (e.g. `<body>` in HTML)
218+ - `builtin`
218219
219220- `namespace`
220221
languages.toml+1−1
@@ -2206,7 +2206,7 @@ indent = { tab-width = 2, unit = " " }
22062206
22072207[[grammar]]
22082208name = "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" }
22102210
22112211[[language]]
22122212name = "prql"
runtime/queries/yuck/highlights.scm+88−47
@@ -1,66 +1,107 @@
1+; Errors
2+
13(ERROR) @error
24
3−(line_comment) @comment
5+; Comments
46
5−; keywords and symbols
7+(comment) @comment
68
7−(keyword) @keyword
8−(symbol) @tag
9+; Operators
910
10−; literals
11+[
12+ "+"
13+ "-"
14+ "*"
15+ "/"
16+ "%"
17+ "||"
18+ "&&"
19+ "=="
20+ "!="
21+ "=~"
22+ ">"
23+ "<"
24+ ">="
25+ "<="
26+ "!"
27+ "?."
28+ "?:"
29+] @operator
1130
12−(bool_literal) @constant.builtin.boolean
13−(num_literal) @constant.numeric
31+(ternary_expression
32+ ["?" ":"] @operator)
1433
15−; strings
16−(string_interpolation
17− (string_interpolation_start) @punctuation.special
18− (string_interpolation_end) @punctuation.special)
34+; Punctuation
35+
36+[ ":" "." "," ] @punctuation.delimiter
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
1949
2050(escape_sequence) @constant.character.escape
2151
22−(string
23− [
24− (unescaped_single_quote_string_fragment)
25− (unescaped_double_quote_string_fragment)
26− (unescaped_backtick_string_fragment)
27− "\""
28− "'"
29− "`"
30− ]) @string
52+(string_interpolation
53+ "${" @punctuation.special
54+ "}" @punctuation.special)
3155
32−; operators and general punctuation
56+[ (string_fragment) "\"" "'" "`" ] @string
3357
34−(unary_expression
35− operator: _ @operator)
58+; Attributes & Fields
3659
37−(binary_expression
38− operator: _ @operator)
60+(keyword) @attribute
3961
40−(ternary_expression
41− operator: _ @operator)
62+; Functions
4263
43−[
44− ":"
45− "."
46− ","
47−] @punctuation.delimiter
64+(function_call
65+ name: (ident) @function)
4866
49−[
50− "("
51− ")"
52− "["
53− "]"
54− "{"
55− "}"
56−] @punctuation.bracket
57−[
58− ":"
59− "."
60− ","
61−] @punctuation.delimiter
67+; Variables
6268
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
64105
65−(index) @variable
66106(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
22 (#set! injection.language "comment"))