Skip to content

Commit

Permalink
feat(matlab)!: replace parser
Browse files Browse the repository at this point in the history
  • Loading branch information
acristoffers committed Jun 13, 2023
1 parent 111a3f4 commit c130051
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 121 deletions.
2 changes: 1 addition & 1 deletion lockfile.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
"revision": "231f3163cd27d48f91a4517cfdf72d167a9ef164"
},
"matlab": {
"revision": "dd95e1fc1b5514aa3a882d5fb8ddbf4683e953f0"
"revision": "36d73a323facb124a6abd8260d75be1ea9b223cc"
},
"menhir": {
"revision": "db7953acb0d5551f207373c81fa07a57d7b085cb"
Expand Down
6 changes: 3 additions & 3 deletions lua/nvim-treesitter/parsers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -926,10 +926,10 @@ list.markdown_inline = {

list.matlab = {
install_info = {
url = "https://github.com/mstanciu552/tree-sitter-matlab",
files = { "src/parser.c" },
url = "https://github.com/acristoffers/tree-sitter-matlab",
files = { "src/parser.c", "src/scanner.c" },
},
maintainers = { "@amaanq" },
maintainers = { "@acristoffers" },
}

list.menhir = {
Expand Down
27 changes: 11 additions & 16 deletions queries/matlab/folds.scm
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
[
(function_definition)

(if_statement)

(for_statement)
(while_statement)

(switch_statement)
(case_statement)

(otherwise_statement)

(try_statement)
(catch_statement)
] @fold
[(if_statement)
(for_statement)
(while_statement)
(switch_statement)
(try_statement)
(function_definition)
(class_definition)
(enumeration)
(events)
(methods)
(properties)] @fold
217 changes: 116 additions & 101 deletions queries/matlab/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,107 +1,122 @@
; Functions
; highlights.scm

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

(parameter_list (identifier) @parameter)

; Keywords

((identifier) @keyword
(#eq? @keyword "end"))

(function_keyword) @keyword.function

[
"return"
] @keyword.return

; Conditionals

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

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

; Repeats

[
"for"
"while"
"break"
"continue"
] @repeat

(for_statement (end) @repeat)
(while_statement (end) @repeat)

; Exceptions

[
"try"
"catch"
] @exception

(try_statement (end) @exception)

; Punctuation

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

[ "{" "}" ] @punctuation.bracket

[ "[" "]" ] @punctuation.bracket

[ "(" ")" ] @punctuation.bracket

; Operators

[
">"
"<"
"=="
"<="
">="
"=<"
"=>"
"~="
"*"
".*"
"/"
"\\"
"./"
"^"
".^"
"+"
"="
"&&"
"||"
] @operator

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

(number) @number

(string) @string

[ "true" "false" ] @boolean

; Comments

(boolean) @boolean
(comment) @comment @spell
(operator) @operator
(keyword) @keyword
(ERROR) @error

; Errors
[";" "," "." ":"] @punctuation.delimiter
["(" ")" "[" "]" "{" "}" ] @punctuation.bracket

(unary_operator
(operator) @number
(number))

(metaclass_operator (identifier) @variable)
(handle_operator (identifier) @function)

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

(struct "." @operator)
(struct . [(function_call
name: (identifier) @variable)
(identifier) @variable])
(struct
[(function_call
name: (identifier) @field)
(identifier) @field])

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

(command
(command_name) @function.call
(command_argument)* @text.literal)

(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)

(arguments (_) @variable)
(global_operator (identifier) @variable)
(persistent_operator (identifier) @variable)

(ERROR) @error
(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
("," (identifier) @variable)*)

(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)

(enum argument: (identifier) @constant)
(events (identifier) @constant)
(validation_functions (identifier) @variable)
(attribute (identifier) @constant)

(function_signature function_name: (identifier) @function)

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

((keyword) @keyword.return
(#eq? @keyword.return "return"))
34 changes: 34 additions & 0 deletions queries/matlab/indents.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
((keyword) @indent.end @indent.branch
(#eq? @indent.end "end")
(#eq? @indent.branch "end"))

[(if_statement)
(for_statement)
(while_statement)
(switch_statement)
(try_statement)
(function_definition)
(class_definition)
(enumeration)
(events)
(methods)
(properties)
] @indent.begin

(elseif_statement elseif: (keyword) @indent.branch)
(else_statement else: (keyword) @indent.branch)
(case case: (keyword) @indent.branch)
(otherwise otherwise: (keyword) @indent.branch)
(catch catch: (keyword) @indent.branch)

((matrix_definition (row) @indent.align)
(#set! indent.open_delimiter "[")
(#set! indent.close_delimiter "]"))
((cell_definition (row) @indent.align)
(#set! indent.open_delimiter "{")
(#set! indent.close_delimiter "}"))
((parenthesized_expression) @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))

(comment) @indent.auto
42 changes: 42 additions & 0 deletions queries/matlab/locals.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(function_definition
(function_output
[(identifier) @definition.var
(multioutput_variable
(identifier) @definition.var
("," (identifier) @definition.var))])?
function_name: (identifier) @definition.function
(function_arguments
(identifier)* @definition.parameter
("," (identifier) @definition.parameter)*)?) @scope

(assignment
variable: (_) @definition.var)
(assignment
(multioutput_variable
(_) @definition.var))

(unary_operator (identifier) @reference)
(binary_operator (identifier) @reference)
(comparison_operator (identifier) @reference)
(boolean_operator (identifier) @reference)
(postfix_operator (identifier) @reference)
(not_operator (identifier) @reference)
(metaclass_operator (identifier) @reference)
(handle_operator (identifier) @reference)

(function_call
name: (identifier) @reference)

(struct . [(function_call
name: (identifier) @reference)
(identifier) @reference])

(range (identifier) @reference)
(condition (identifier) @reference)
(iterator . (identifier) @definition.var)
(iterator (identifier) @reference)
(parfor_options (identifier) @reference)
(lambda (arguments (identifier) @definition.parameter))
(global_operator (identifier) @definition.var)
(persistent_operator (identifier) @definition.var)
(catch (captured_exception) @definition.var)

0 comments on commit c130051

Please sign in to comment.