From e1e243af7c4d28c551fea80300f9791423ca9ba8 Mon Sep 17 00:00:00 2001 From: Erasin Date: Sun, 28 Apr 2024 18:06:18 +0800 Subject: [PATCH] Add pest support Support [pest-parser](https://github.com/pest-parser) - [pest-language-server](https://github.com/pest-parser/pest-ide-tools) - [tree-sitter-pest](https://github.com/pest-parser/tree-sitter-pest) close #7878 --- book/src/generated/lang-support.md | 1 + languages.toml | 22 +++++++++++++ runtime/queries/pest/highlights.scm | 49 ++++++++++++++++++++++++++++ runtime/queries/pest/indents.scm | 9 +++++ runtime/queries/pest/injections.scm | 7 ++++ runtime/queries/pest/textobjects.scm | 8 +++++ 6 files changed, 96 insertions(+) create mode 100644 runtime/queries/pest/highlights.scm create mode 100644 runtime/queries/pest/indents.scm create mode 100644 runtime/queries/pest/injections.scm create mode 100644 runtime/queries/pest/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 45cc1384d7ec8..77d304cc6df11 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -141,6 +141,7 @@ | passwd | ✓ | | | | | pem | ✓ | | | | | perl | ✓ | ✓ | ✓ | `perlnavigator` | +| pest | ✓ | ✓ | ✓ | `pest-language-server` | | php | ✓ | ✓ | ✓ | `intelephense` | | php-only | ✓ | | | | | pkgbuild | ✓ | ✓ | ✓ | `pkgbuild-language-server`, `bash-language-server` | diff --git a/languages.toml b/languages.toml index 7e858b05627db..9f0fa1faca4f7 100644 --- a/languages.toml +++ b/languages.toml @@ -67,6 +67,7 @@ openscad-lsp = { command = "openscad-lsp", args = ["--stdio"] } pasls = { command = "pasls", args = [] } pbkit = { command = "pb", args = [ "lsp" ] } perlnavigator = { command = "perlnavigator", args= ["--stdio"] } +pest-language-server = { command = "pest-language-server" } prisma-language-server = { command = "prisma-language-server", args = ["--stdio"] } purescript-language-server = { command = "purescript-language-server", args = ["--stdio"] } pylsp = { command = "pylsp" } @@ -3558,3 +3559,24 @@ language-servers = [] [[grammar]] name = "move" source = { git = "https://github.com/tzakian/tree-sitter-move", rev = "8bc0d1692caa8763fef54d48068238d9bf3c0264" } + +[[language]] +name = "pest" +scope = "source.pest" +injection-regex = "pest" +file-types = ["pest"] +comment-tokens = ["//", "///", "//!"] +block-comment-tokens = { start = "/*", end = "*/" } +indent = { tab-width = 4, unit = " " } +roots = [] +language-servers = ["pest-language-server"] + +[language.auto-pairs] +'(' = ')' +'{' = '}' +'[' = ']' +'"' = '"' + +[[grammar]] +name = "pest" +source = { git = "https://github.com/pest-parser/tree-sitter-pest", rev = "a8a98a824452b1ec4da7f508386a187a2f234b85" } diff --git a/runtime/queries/pest/highlights.scm b/runtime/queries/pest/highlights.scm new file mode 100644 index 0000000000000..9d6f13c2ac4a2 --- /dev/null +++ b/runtime/queries/pest/highlights.scm @@ -0,0 +1,49 @@ +(line_comment) @comment +(block_comment) @comment + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +((identifier) @variable) +((builtin) @type.builtin) +((const) @constant) + +[ + (string) + (character) +] @string + +[ + "_" + "@" + "$" +]@keyword.storage.modifier + +[ + "~" + "|" + "=" + "+" + "*" + "&" + "^" + "!" + "?" + ".." +] @operator + +[ + "PUSH" + "PEEK" + "POP" + "SOI" + "EOI" + "ANY" +] @keyword + diff --git a/runtime/queries/pest/indents.scm b/runtime/queries/pest/indents.scm new file mode 100644 index 0000000000000..51042f905f2af --- /dev/null +++ b/runtime/queries/pest/indents.scm @@ -0,0 +1,9 @@ +[ + (expression) +] @indent + +[ + "]" + "}" + ")" +] @outdent diff --git a/runtime/queries/pest/injections.scm b/runtime/queries/pest/injections.scm new file mode 100644 index 0000000000000..0a79c8f83c340 --- /dev/null +++ b/runtime/queries/pest/injections.scm @@ -0,0 +1,7 @@ +((line_comment) @injection.content + (#set! injection.language "comment") + (#set! injection.include-children)) + +((block_comment) @injection.content + (#set! injection.language "comment") + (#set! injection.include-children)) diff --git a/runtime/queries/pest/textobjects.scm b/runtime/queries/pest/textobjects.scm new file mode 100644 index 0000000000000..75ccd09eb24b7 --- /dev/null +++ b/runtime/queries/pest/textobjects.scm @@ -0,0 +1,8 @@ +(grammar_rule (_) @class.inside) @class.around +(term (_) @entry.inside) @entry.around + +(line_comment) @comment.inside +(line_comment)+ @comment.around + +(block_comment) @comment.inside +(block_comment)+ @comment.around