summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorg-s-k2022-12-17 19:44:08 +0000
committerGitHub2022-12-17 19:44:08 +0000
commit042d03269ecbe68e0461548bcf6918324c967bbb (patch)
treec6cea30f1401ce6d44ae55b2b3e99637847e855b
parentaecb524e503363c2eed2a5a72d8fd881aae18e4b (diff)
Add support for MATLAB/Octave files (#5192)
-rw-r--r--book/src/generated/lang-support.md1
-rw-r--r--languages.toml13
-rw-r--r--runtime/queries/matlab/highlights.scm97
3 files changed, 111 insertions, 0 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index 73e0bfcd..1a3aed79 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -78,6 +78,7 @@
| make | ✓ | | | |
| markdown | ✓ | | | `marksman` |
| markdown.inline | ✓ | | | |
+| matlab | ✓ | | | |
| mermaid | ✓ | | | |
| meson | ✓ | | ✓ | |
| mint | | | | `mint` |
diff --git a/languages.toml b/languages.toml
index 42495e5c..8972a6e9 100644
--- a/languages.toml
+++ b/languages.toml
@@ -2068,3 +2068,16 @@ indent = { tab-width = 4, unit = " " }
[[grammar]]
name = "mermaid"
source = { git = "https://github.com/monaqa/tree-sitter-mermaid", rev = "d787c66276e7e95899230539f556e8b83ee16f6d" }
+
+[[language]]
+name = "matlab"
+scope = "source.m"
+file-types = ["m"]
+comment-token = "%"
+shebangs = ["octave-cli", "matlab"]
+roots = []
+indent = { tab-width = 2, unit = " " }
+
+[[grammar]]
+name = "matlab"
+source = { git = "https://github.com/mstanciu552/tree-sitter-matlab", rev = "2d5d3d5193718a86477d4335aba5b34e79147326" }
diff --git a/runtime/queries/matlab/highlights.scm b/runtime/queries/matlab/highlights.scm
new file mode 100644
index 00000000..c0e23e91
--- /dev/null
+++ b/runtime/queries/matlab/highlights.scm
@@ -0,0 +1,97 @@
+ ; highlights.scm
+
+function_keyword: (function_keyword) @keyword.function
+
+(function_definition
+function_name: (identifier) @function
+(end) @function)
+
+(parameter_list (identifier) @variable.parameter)
+
+[
+ "if"
+ "elseif"
+ "else"
+ "switch"
+ "case"
+ "otherwise"
+] @keyword.control.conditional
+
+(if_statement (end) @keyword.control.conditional)
+(switch_statement (end) @keyword.control.conditional)
+
+["for" "while"] @keyword.control.repeat
+(for_statement (end) @keyword.control.repeat)
+(while_statement (end) @keyword.control.repeat)
+
+["try" "catch"] @keyword.control.exception
+(try_statement (end) @keyword.control.exception)
+
+(function_definition end: (end) @keyword)
+
+["return" "break" "continue"] @keyword.return
+
+(
+(identifier) @constant.builtin
+(#any-of? @constant.builtin "true" "false")
+)
+
+(
+ (identifier) @constant.builtin
+ (#eq? @constant.builtin "end")
+)
+
+;; Punctuations
+
+[";" ","] @punctuation.special
+(argument_list "," @punctuation.delimiter)
+(vector_definition ["," ";"] @punctuation.delimiter)
+(cell_definition ["," ";"] @punctuation.delimiter)
+":" @punctuation.delimiter
+(parameter_list "," @punctuation.delimiter)
+(return_value "," @punctuation.delimiter)
+
+; ;; Brackets
+
+[
+ "("
+ ")"
+ "["
+ "]"
+ "{"
+ "}"
+] @punctuation.bracket
+
+;; Operators
+"=" @operator
+(operation [ ">"
+ "<"
+ "=="
+ "<="
+ ">="
+ "=<"
+ "=>"
+ "~="
+ "*"
+ ".*"
+ "/"
+ "\\"
+ "./"
+ "^"
+ ".^"
+ "+"] @operator)
+
+;; boolean operator
+[
+ "&&"
+ "||"
+] @operator
+
+;; Number
+(number) @constant.numeric
+
+;; String
+(string) @string
+
+;; Comment
+(comment) @comment