From a8fd33ac012a79069ef1409503a2edcf3a585153 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Thu, 6 Jan 2022 09:00:00 -0600 Subject: [PATCH] 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 --- .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 +++++++ 7 files changed, 87 insertions(+) create mode 160000 helix-syntax/languages/tree-sitter-regex create mode 100644 runtime/queries/regex/highlights.scm diff --git a/.gitmodules b/.gitmodules index 9297708a6..f6a0fdc49 100644 --- a/.gitmodules +++ b/.gitmodules @@ -190,3 +190,7 @@ path = helix-syntax/languages/tree-sitter-git-rebase url = https://github.com/the-mikedavis/tree-sitter-git-rebase.git shallow = true +[submodule "helix-syntax/languages/tree-sitter-regex"] + path = helix-syntax/languages/tree-sitter-regex + url = https://github.com/tree-sitter/tree-sitter-regex.git + shallow = true diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index a1fbf1724..daf8b0061 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -38,6 +38,7 @@ | protobuf | ✓ | | ✓ | | | python | ✓ | ✓ | ✓ | `pylsp` | | racket | | | | `racket` | +| regex | ✓ | | | | | ruby | ✓ | | ✓ | `solargraph` | | rust | ✓ | ✓ | ✓ | `rust-analyzer` | | scala | ✓ | | ✓ | `metals` | diff --git a/helix-syntax/languages/tree-sitter-regex b/helix-syntax/languages/tree-sitter-regex new file mode 160000 index 000000000..e1cfca3c7 --- /dev/null +++ b/helix-syntax/languages/tree-sitter-regex @@ -0,0 +1 @@ +Subproject commit e1cfca3c79896ff79842f057ea13e529b66af636 diff --git a/languages.toml b/languages.toml index e8329fe71..3e2e7b15c 100644 --- a/languages.toml +++ b/languages.toml @@ -530,3 +530,10 @@ file-types = ["git-rebase-todo"] injection-regex = "git-rebase" comment-token = "#" indent = { tab-width = 2, unit = " " } + +[[language]] +name = "regex" +scope = "source.regex" +injection-regex = "regex" +file-types = ["regex"] +roots = [] diff --git a/runtime/queries/elixir/injections.scm b/runtime/queries/elixir/injections.scm index 321c90add..8370a0d8d 100644 --- a/runtime/queries/elixir/injections.scm +++ b/runtime/queries/elixir/injections.scm @@ -1,2 +1,9 @@ ((comment) @injection.content (#set! injection.language "comment")) + +((sigil + (sigil_name) @_sigil_name + (quoted_content) @injection.content) + (#match? @_sigil_name "^(r|R)$") + (#set! injection.language "regex") + (#set! injection.combined)) diff --git a/runtime/queries/regex/highlights.scm b/runtime/queries/regex/highlights.scm new file mode 100644 index 000000000..9376caa92 --- /dev/null +++ b/runtime/queries/regex/highlights.scm @@ -0,0 +1,53 @@ +; upstream: https://github.com/tree-sitter/tree-sitter-regex/blob/e1cfca3c79896ff79842f057ea13e529b66af636/queries/highlights.scm + +[ + "(" + ")" + "(?" + "(?:" + "(?<" + ">" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "*" + "+" + "|" + "=" + "<=" + "!" + "