on master help sign in
add tree-sitter-regex (#1362)

* add tree-sitter-regex * adapt regex highlights from upstream * inject regex into elixir sigil_r/2 and sigil_R/2 * generate lang-support docs * capture interesting nodes in character-ranges * make $.character_class captures more consistent * fix fallthrough behavior for character classes * capture pattern characters as 'string' * use latest tree-sitter-regex * set elixir regex injections as combined * add link to upstream queries * inject regex in rust into 'Regex::new' raw string literals

commita8fd33ac012a79069ef1409503a2edcf3a585153 authorMichael Davis <mcarsondavis@gmail.com> dateThu 6 Jan 2022, 09:00 (5 years ago) parent2e02a1d
7 files changed+87
.gitmodules+4 book/src/generated/lang-support.md+1 helix-syntax/languages/tree-sitter-regex+1 languages.toml+7 runtime/queries/elixir/injections.scm+7 runtime/queries/regex/highlights.scm+53 runtime/queries/rust/injections.scm+14
.gitmodules+4
@@ -190,3 +190,7 @@
190190 path = helix-syntax/languages/tree-sitter-git-rebase
191191 url = https://github.com/the-mikedavis/tree-sitter-git-rebase.git
192192 shallow = true
193+[submodule "helix-syntax/languages/tree-sitter-regex"]
194+ path = helix-syntax/languages/tree-sitter-regex
195+ url = https://github.com/tree-sitter/tree-sitter-regex.git
196+ shallow = true
book/src/generated/lang-support.md+1
@@ -38,6 +38,7 @@
3838| protobuf | ✓ | | ✓ | |
3939| python | ✓ | ✓ | ✓ | `pylsp` |
4040| racket | | | | `racket` |
41+| regex | ✓ | | | |
4142| ruby | ✓ | | ✓ | `solargraph` |
4243| rust | ✓ | ✓ | ✓ | `rust-analyzer` |
4344| scala | ✓ | | ✓ | `metals` |
helix-syntax/languages/tree-sitter-regexnew file+1

Submodule changed.

languages.toml+7
@@ -530,3 +530,10 @@ file-types = ["git-rebase-todo"]
530530injection-regex = "git-rebase"
531531comment-token = "#"
532532indent = { tab-width = 2, unit = " " }
533+
534+[[language]]
535+name = "regex"
536+scope = "source.regex"
537+injection-regex = "regex"
538+file-types = ["regex"]
539+roots = []
runtime/queries/elixir/injections.scm+7
@@ -1,2 +1,9 @@
11((comment) @injection.content
22 (#set! injection.language "comment"))
3+
4+((sigil
5+ (sigil_name) @_sigil_name
6+ (quoted_content) @injection.content)
7+ (#match? @_sigil_name "^(r|R)$")
8+ (#set! injection.language "regex")
9+ (#set! injection.combined))
runtime/queries/regex/highlights.scmnew file+53
@@ -0,0 +1,53 @@
1+; upstream: https://github.com/tree-sitter/tree-sitter-regex/blob/e1cfca3c79896ff79842f057ea13e529b66af636/queries/highlights.scm
2+
3+[
4+ "("
5+ ")"
6+ "(?"
7+ "(?:"
8+ "(?<"
9+ ">"
10+ "["
11+ "]"
12+ "{"
13+ "}"
14+] @punctuation.bracket
15+
16+[
17+ "*"
18+ "+"
19+ "|"
20+ "="
21+ "<="
22+ "!"
23+ "<!"
24+ "?"
25+] @operator
26+
27+[
28+ (identity_escape)
29+ (control_letter_escape)
30+ (character_class_escape)
31+ (control_escape)
32+ (start_assertion)
33+ (end_assertion)
34+ (boundary_assertion)
35+ (non_boundary_assertion)
36+] @constant.character.escape
37+
38+(group_name) @property
39+
40+(count_quantifier
41+ [
42+ (decimal_digits) @constant.numeric
43+ "," @punctuation.delimiter
44+ ])
45+
46+(character_class
47+ [
48+ "^" @operator
49+ (class_range "-" @operator)
50+ ])
51+
52+(class_character) @constant.character
53+(pattern_character) @string
runtime/queries/rust/injections.scm+14
@@ -10,3 +10,17 @@
1010 (token_tree) @injection.content)
1111 (#set! injection.language "rust")
1212 (#set! injection.include-children))
13+
14+(call_expression
15+ function: (scoped_identifier
16+ path: (identifier) @_regex (#eq? @_regex "Regex")
17+ name: (identifier) @_new (#eq? @_new "new"))
18+ arguments: (arguments (raw_string_literal) @injection.content)
19+ (#set! injection.language "regex"))
20+
21+(call_expression
22+ function: (scoped_identifier
23+ path: (scoped_identifier (identifier) @_regex (#eq? @_regex "Regex") .)
24+ name: (identifier) @_new (#eq? @_new "new"))
25+ arguments: (arguments (raw_string_literal) @injection.content)
26+ (#set! injection.language "regex"))