Skip to content

Commit

Permalink
Add matlab grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
acristoffers committed Jun 15, 2023
1 parent ffe9ab0 commit 89037f9
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 4 deletions.
14 changes: 10 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Add `MATLAB` grammar

## 0.12.18 - 2023-03-11
- Add `Meson` grammar

Expand Down
167 changes: 167 additions & 0 deletions queries/matlab/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
; highlights.scm

;; Emacs uses some different conventions for highlights.

(unary_operator
(operator) @number
(number))

(unary_operator
(operator) @operator
(_))
(binary_operator
(operator) @operator)
(comparison_operator
(operator) @operator)
(boolean_operator
(operator) @operator)
(postfix_operator
(operator) @operator)
(not_operator
(operator) @operator)
(metaclass_operator
(operator) @operator)
(handle_operator
(operator) @operator)

(assignment
variable: (_) @variable)
(assignment
(multioutput_variable
(_) @variable))

(struct "." @operator)

(function_call
name: (identifier) @function.call
("@" @operator (superclass) @type)?)

(command
(command_name) @function.call
(command_argument)* @string)

(spread_operator) @constant

(range
":" @operator)

(if_statement
if: (keyword) @conditional
(elseif_statement
elseif: (keyword) @conditional)*
(else_statement
else: (keyword) @conditional)*
end: (keyword) @conditional)

(for_statement
(keyword) @repeat
(identifier)? @variable
(block)
end: (keyword) @repeat)

(while_statement
while: (keyword) @repeat
end: (keyword) @repeat)

(switch_statement
switch: (keyword) @conditional
(case
case: (keyword) @conditional)+
(otherwise
otherwise: (keyword) @conditional)+
end: (keyword) @conditional)

(lambda
(operator) @operator
(arguments
(_) @variable)?)

(global_operator
(keyword) @keyword
(identifier) @variable)

(persistent_operator
(keyword) @keyword
(identifier) @variable)

(function_definition
(keyword) @keyword.function
(identifier) @function
(end_function
(keyword) @keyword.function)?)

(function_output
[(identifier) @variable
(multioutput_variable
(identifier) @variable
("," (identifier) @variable))])

(function_arguments
(identifier)* @variable.parameter
("," (identifier) @variable.parameter)*)

(try_statement
try: (keyword) @exception
end: (keyword) @exception)
(catch
catch: (keyword) @exception
(captured_exception) @variable)

(class_definition
classdef: (keyword) @keyword.function
(attributes
(identifier) @constant)?
class_name: (identifier) @type.definition
(superclasses
(identifier) @type)?
end: (keyword) @keyword.function)

(enumeration
enumeration: (keyword) @structure
(enum
argument: (identifier) @constant)
end: (keyword) @structure)

(events
events: (keyword) @structure
(identifier) @constant
end: (keyword) @structure)

(methods
methods: (keyword) @structure
end: (keyword) @structure)

(function_signature
(function_output)?
function_name: (identifier) @function
(function_arguments)?)

(properties
properties: (keyword) @structure
end: (keyword) @structure)

(property
(property_name) @constant
(class)? @type)

(validation_functions
(identifier) @type)

(attribute
(identifier) @constant)

(keyword) @keyword

(string) @string
(string) @spell
(formatting_sequence) @string.special
(escape_sequence) @string.escape

(number) @number
(boolean) @constant.builtin
(comment) @comment
(comment) @spell

[";" "," "." ":"] @punctuation.delimiter

["(" ")" "[" "]" "{" "}" ] @punctuation.bracket
1 change: 1 addition & 0 deletions repos/matlab
Submodule matlab added at c7c807
1 change: 1 addition & 0 deletions tree-sitter-langs.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 89037f9

Please sign in to comment.