From eea9ab7a4503f712e9df36c6055ebcb3514c91bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lan=20Cr=C3=ADstoffer?= Date: Mon, 12 Jun 2023 16:37:27 +0200 Subject: [PATCH] Add matlab grammar --- .gitmodules | 14 ++- CHANGELOG.md | 2 + queries/matlab/highlights.scm | 177 ++++++++++++++++++++++++++++++++++ repos/matlab | 1 + tree-sitter-langs.el | 1 + 5 files changed, 191 insertions(+), 4 deletions(-) create mode 100644 queries/matlab/highlights.scm create mode 160000 repos/matlab diff --git a/.gitmodules b/.gitmodules index 603fe3ea..215f143b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -186,7 +186,7 @@ url = https://github.com/LumaKernel/tree-sitter-prisma branch = master update = none - ignore = dirty + ignore = dirty [submodule "repos/haskell"] path = repos/haskell url = https://github.com/tree-sitter/tree-sitter-haskell @@ -253,9 +253,9 @@ [submodule "repos/fennel"] path = repos/fennel url = https://github.com/TravonteD/tree-sitter-fennel - branch = master - update = none - ignore = dirty + branch = master + update = none + ignore = dirty [submodule "repos/clojure"] path = repos/clojure url = https://github.com/sogaiu/tree-sitter-clojure @@ -268,3 +268,9 @@ branch = master update = none ignore = dirty +[submodule "repos/matlab"] + path = repos/matlab + url = https://github.com/acristoffers/tree-sitter-matlab + branch = main + update = none + ignore = dirty diff --git a/CHANGELOG.md b/CHANGELOG.md index a7fee717..c8681512 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Add `MATLAB` grammar + ## 0.12.20 - 2023-06-22 - Bump `go` grammar diff --git a/queries/matlab/highlights.scm b/queries/matlab/highlights.scm new file mode 100644 index 00000000..83bd8347 --- /dev/null +++ b/queries/matlab/highlights.scm @@ -0,0 +1,177 @@ +; attribute +; comment +; constant +; constant.builtin +; constructor +; doc +; embedded +; escape +; function +; function.builtin +; function.call +; function.macro +; function.special +; keyword +; label +; method +; method.call +; number +; operator +; property +; property.definition +; punctuation +; punctuation.bracket +; punctuation.delimiter +; punctuation.special +; string +; string.special +; tag +; type +; type.argument +; type.builtin +; type.parameter +; type.super +; variable +; variable.builtin +; variable.parameter +; variable.special + +; Errors + +(ERROR) @error + +; Constants + +(events (identifier) @constant) +(attribute (identifier) @constant) + +"~" @constant.builtin + +; Fields/Properties + +(field_expression field: (identifier) @property) +(superclass "." (identifier) @property) +(property_name "." (identifier) @property) +(property name: (identifier) @property) + +; Types + +(class_definition name: (identifier) @type) +(attributes (identifier) @constant) +(enum . (identifier) @type) + +; Functions + +(function_definition + "function" @keyword + name: (identifier) @function + [ "end" "endfunction" ]? @keyword) + +(function_signature name: (identifier) @function) + +(function_call name: (identifier) @function.call) + +(handle_operator (identifier) @function) +(validation_functions (identifier) @function) + +(command (command_name) @function.macro) +(command_argument) @string + +(return_statement) @keyword + +; Parameters + +(lambda (arguments (identifier) @variable.parameter)) +(function_arguments (identifier) @variable.parameter) + +; Assignments + +(assignment left: (_) @variable) +(multioutput_variable (_) @variable) + +; Operators + +(unary_operator ["+" "-"] @number) + +[ + "+" + ".+" + "-" + ".*" + "*" + ".*" + "/" + "./" + "\\" + ".\\" + "^" + ".^" + "'" + ".'" + "|" + "&" + "?" + "@" + "<" + "<=" + ">" + ">=" + "==" + "~=" + "=" + "&&" + "||" + ":" +] @operator + +; Conditionals + +(if_statement [ "if" "end" ] @keyword) +(elseif_clause "elseif" @keyword) +(else_clause "else" @keyword) +(switch_statement [ "switch" "end" ] @keyword) +(case_clause "case" @keyword) +(otherwise_clause "otherwise" @keyword) +(break_statement) @keyword + +; Repeats + +(for_statement [ "for" "parfor" "end" ] @keyword) +(while_statement [ "while" "end" ] @keyword) +(continue_statement) @keyword + +; Exceptions + +(try_statement [ "try" "end" ] @keyword) +(catch_clause "catch" @keyword) + +; Punctuation + +[ ";" "," "." ] @punctuation.delimiter +[ "(" ")" "[" "]" "{" "}" ] @punctuation.bracket + +; Literals + +(escape_sequence) @escape +(formatting_sequence) @escape +(string) @string +(number) @number +(boolean) @constant.builtin + +; Comments + +[ (comment) (line_continuation) ] @comment @spell + +; Keywords + +[ + "arguments" + "classdef" + "end" + "enumeration" + "events" + "global" + "methods" + "persistent" + "properties" +] @keyword diff --git a/repos/matlab b/repos/matlab new file mode 160000 index 00000000..0e493c80 --- /dev/null +++ b/repos/matlab @@ -0,0 +1 @@ +Subproject commit 0e493c806c442753ab8697963515457f88d2a399 diff --git a/tree-sitter-langs.el b/tree-sitter-langs.el index cfb66238..8fce6c3e 100644 --- a/tree-sitter-langs.el +++ b/tree-sitter-langs.el @@ -129,6 +129,7 @@ See `tree-sitter-langs-repos'." (jsonc-mode . json) (julia-mode . julia) (lua-mode . lua) + (matlab-mode . matlab) (meson-mode . meson) (ocaml-mode . ocaml) (perl-mode . perl)