Skip to content

Commit

Permalink
Add support for MATLAB/Octave files
Browse files Browse the repository at this point in the history
  • Loading branch information
g-s-k committed Dec 17, 2022
1 parent 3e68876 commit b96c103
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
| make || | | |
| markdown || | | `marksman` |
| markdown.inline || | | |
| matlab || | | |
| mermaid || | | |
| meson || || |
| mint | | | | `mint` |
Expand Down
13 changes: 13 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2056,3 +2056,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" }
99 changes: 99 additions & 0 deletions runtime/queries/matlab/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
; highlights.scm

function_keyword: (function_keyword) @keyword.function

(function_definition
function_name: (identifier) @function
(end) @function)

(parameter_list (identifier) @parameter)

[
"if"
"elseif"
"else"
"switch"
"case"
"otherwise"
] @conditional

(if_statement (end) @conditional)
(switch_statement (end) @conditional)

["for" "while"] @repeat
(for_statement (end) @repeat)
(while_statement (end) @repeat)

["try" "catch"] @exception
(try_statement (end) @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

[";" ","] @character.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) @number

;; String
(string) @string
(string) @spell

;; Comment
(comment) @comment
(comment) @spell

0 comments on commit b96c103

Please sign in to comment.