From 467d9bbeca1b7c41f050797db89de7a5128ccd9b Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Sun, 24 Mar 2024 21:00:32 +0100 Subject: [PATCH 1/3] feat: Add `Ohm` language support Hope this commit makes it into release :) --- book/src/generated/lang-support.md | 1 + languages.toml | 22 +++++ runtime/queries/ohm/highlights.scm | 122 ++++++++++++++++++++++++++++ runtime/queries/ohm/indents.scm | 37 +++++++++ runtime/queries/ohm/injections.scm | 7 ++ runtime/queries/ohm/textobjects.scm | 40 +++++++++ 6 files changed, 229 insertions(+) create mode 100644 runtime/queries/ohm/highlights.scm create mode 100644 runtime/queries/ohm/indents.scm create mode 100644 runtime/queries/ohm/injections.scm create mode 100644 runtime/queries/ohm/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index b74a8cdb7cd5..2030949eb465 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -128,6 +128,7 @@ | ocaml | ✓ | | ✓ | `ocamllsp` | | ocaml-interface | ✓ | | | `ocamllsp` | | odin | ✓ | | ✓ | `ols` | +| ohm | ✓ | ✓ | ✓ | | | opencl | ✓ | ✓ | ✓ | `clangd` | | openscad | ✓ | | | `openscad-lsp` | | org | ✓ | | | | diff --git a/languages.toml b/languages.toml index cbbfc5a91d3a..9eb80414f36b 100644 --- a/languages.toml +++ b/languages.toml @@ -3408,3 +3408,25 @@ formatter = { command = "prettier", args = ['--parser', 'glimmer'] } [[grammar]] name = "glimmer" source = { git = "https://github.com/ember-tooling/tree-sitter-glimmer", rev = "5dc6d1040e8ff8978ff3680e818d85447bbc10aa" } + +[[language]] +name = "ohm" +scope = "source.ohm" +injection-regex = "ohm" +file-types = ["ohm"] +comment-token = "//" +block-comment-tokens = [ + { start = "/*", end = "*/" }, + { start = "/**", end = "*/" }, +] +indent = { tab-width = 2, unit = " " } + +[language.auto-pairs] +'"' = '"' +'{' = '}' +'(' = ')' +'<' = '>' + +[[grammar]] +name = "ohm" +source = { git = "https://github.com/novusnota/tree-sitter-ohm", rev = "80f14f0e477ddacc1e137d5ed8e830329e3fb7a3" } diff --git a/runtime/queries/ohm/highlights.scm b/runtime/queries/ohm/highlights.scm new file mode 100644 index 000000000000..3e285c5c342a --- /dev/null +++ b/runtime/queries/ohm/highlights.scm @@ -0,0 +1,122 @@ +; See: https://docs.helix-editor.com/master/themes.html#syntax-highlighting + +; attribute +; --------- + +(case_name) @attribute + +; comment.line +; ------------ + +[ + (singleline_comment) + (rule_descr) +] @comment.line + +; comment.block +; ------------- + +(multiline_comment) @comment.block + +; function.method +; --------------- + +(rule + name: (identifier) @function.method) + +; function.builtin +; ---------------- + +; Lexical +((identifier) @function.builtin + (#any-of? @function.builtin + "any" + "alnum" + "end" + "digit" "hexDigit" + "letter" + "space" + "lower" "upper" "caseInsensitive" + "listOf" "nonemptyListOf" "emptyListOf" + "applySyntactic") + (#is-not? local)) + +; Syntactic +((identifier) @function.builtin + (#any-of? @function.builtin "ListOf" "NonemptyListOf" "EmptyListOf") + (#is-not? local)) + +; function.method (continuing) +; --------------- + +(term + base: (identifier) @function.method) + +; string.special +; -------------- + +(escape_char) @string.special + +; string +; ------ + +[ + (terminal_string) + (one_char_terminal) +] @string + +; type +; ---- + +(super_grammar + name: (identifier) @type) + +(grammar + name: (identifier) @type) + +; operator +; -------- + +[ + ; "=" ":=" "+=" + (define) (override) (extend) + + ; "&" "~" + (lookahead) (negative_lookahead) + + ; "#" + (lexification) + + ; "*" "+" "?" + (zero_or_more) (one_or_more) (zero_or_one) + + ; "..." + (super_splice) + + "<:" ".." "|" +] @operator + +; punctuation.bracket +; ------------------- + +[ + "<" + ">" + "{" + "}" +] @punctuation.bracket + +(alt + "(" @punctuation.bracket + ")" @punctuation.bracket) + +; punctuation.delimiter +; --------------------- + +"," @punctuation.delimiter + +; variable.parameter +; ------------------ + +(formals + (identifier) @variable.parameter) diff --git a/runtime/queries/ohm/indents.scm b/runtime/queries/ohm/indents.scm new file mode 100644 index 000000000000..f56119aecff2 --- /dev/null +++ b/runtime/queries/ohm/indents.scm @@ -0,0 +1,37 @@ +; See: https://docs.helix-editor.com/guides/indent.html + +; indent +; ------ + +[ + ; <..., ...> + (formals) + (params) + + ; (...| ...) + (alt) +] @indent + +; outdent +; ------- + +[ + "}" + ")" + ">" +] @outdent + +; align +; ----- + +; | ... | ... +(rule_body + . (top_level_term) @anchor + (#set! "scope" "tail")) @align + +; N/A or unused: +; -------------- +; indent.always +; outdent.always +; extend +; extend.prevent-once diff --git a/runtime/queries/ohm/injections.scm b/runtime/queries/ohm/injections.scm new file mode 100644 index 000000000000..de6f9b5af24d --- /dev/null +++ b/runtime/queries/ohm/injections.scm @@ -0,0 +1,7 @@ +; See: https://docs.helix-editor.com/guides/injection.html + +((singleline_comment) @injection.content + (#set! injection.language "comment")) + +((multiline_comment) @injection.content + (#set! injection.language "comment")) \ No newline at end of file diff --git a/runtime/queries/ohm/textobjects.scm b/runtime/queries/ohm/textobjects.scm new file mode 100644 index 000000000000..855ad8de7181 --- /dev/null +++ b/runtime/queries/ohm/textobjects.scm @@ -0,0 +1,40 @@ +; See: https://docs.helix-editor.com/guides/textobject.html + +; function.inside & around +; ------------------------ + +(rule + body: (_) @function.inside) @function.around + +; class.inside & around +; --------------------- + +(grammar + body: (_) @class.inside) @class.around + +; parameter.inside & around +; ------------------------- + +(formals + ((_) @parameter.inside . ","? @parameter.around) @parameter.around) + +(rule_body + ((_) @parameter.inside . "|"? @parameter.around) @parameter.around) + +(params + ((_) @parameter.inside . ","? @parameter.around) @parameter.around) + +(alt + ((_) @parameter.inside . "|"? @parameter.around) @parameter.around) + +; comment.inside +; -------------- + +(multiline_comment)+ @comment.inside +(singleline_comment)+ @comment.inside + +; comment.around +; -------------- + +(multiline_comment)+ @comment.around +(singleline_comment)+ @comment.around From bed7160123d20623fb3ff569a8028a78f801d56f Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Sun, 24 Mar 2024 23:00:07 +0100 Subject: [PATCH 2/3] Update runtime/queries/ohm/highlights.scm Co-authored-by: Michael Davis --- runtime/queries/ohm/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/queries/ohm/highlights.scm b/runtime/queries/ohm/highlights.scm index 3e285c5c342a..68477aacc5aa 100644 --- a/runtime/queries/ohm/highlights.scm +++ b/runtime/queries/ohm/highlights.scm @@ -55,7 +55,7 @@ ; string.special ; -------------- -(escape_char) @string.special +(escape_char) @constant.character.escape ; string ; ------ From fd30d4d6988c4d937947a639d58952afaf79ab22 Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Sun, 24 Mar 2024 23:01:19 +0100 Subject: [PATCH 3/3] chore: final newline --- runtime/queries/ohm/injections.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/queries/ohm/injections.scm b/runtime/queries/ohm/injections.scm index de6f9b5af24d..dc50a7654705 100644 --- a/runtime/queries/ohm/injections.scm +++ b/runtime/queries/ohm/injections.scm @@ -4,4 +4,4 @@ (#set! injection.language "comment")) ((multiline_comment) @injection.content - (#set! injection.language "comment")) \ No newline at end of file + (#set! injection.language "comment"))