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 23, 2023
1 parent 2e1d165 commit 2c53c6c
Show file tree
Hide file tree
Showing 5 changed files with 195 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.20 - 2023-06-22
- Bump `go` grammar

Expand Down
181 changes: 181 additions & 0 deletions queries/matlab/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
; 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 object: (identifier) @variable)
(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

; Assignments

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

; Parameters

(function_arguments (identifier) @variable.parameter)

; 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) @string.special
(string) @string
(number) @number
(boolean) @constant.builtin

; Comments

[ (comment) (line_continuation) ] @comment @spell

; Keywords

[
"arguments"
"classdef"
"end"
"enumeration"
"events"
"global"
"methods"
"persistent"
"properties"
] @keyword

; Variables

(identifier) @variable
1 change: 1 addition & 0 deletions repos/matlab
Submodule matlab added at c7e4cb
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 2c53c6c

Please sign in to comment.