feat(matlab)!: replace parser

This commit is contained in:
Álan Crístoffer 2023-06-12 10:15:41 +02:00 committed by Christian Clason
parent 3f6c2de149
commit df3f47a508
6 changed files with 180 additions and 83 deletions

View file

@ -303,7 +303,7 @@
"revision": "231f3163cd27d48f91a4517cfdf72d167a9ef164" "revision": "231f3163cd27d48f91a4517cfdf72d167a9ef164"
}, },
"matlab": { "matlab": {
"revision": "dd95e1fc1b5514aa3a882d5fb8ddbf4683e953f0" "revision": "47cd9bde20c53a106cbd9ab1bd18fbfc600264e6"
}, },
"menhir": { "menhir": {
"revision": "db7953acb0d5551f207373c81fa07a57d7b085cb" "revision": "db7953acb0d5551f207373c81fa07a57d7b085cb"

View file

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

View file

@ -1,16 +1,11 @@
[ [(if_statement)
(function_definition) (for_statement)
(while_statement)
(if_statement) (switch_statement)
(try_statement)
(for_statement) (function_definition)
(while_statement) (class_definition)
(enumeration)
(switch_statement) (events)
(case_statement) (methods)
(properties)] @fold
(otherwise_statement)
(try_statement)
(catch_statement)
] @fold

View file

@ -1,106 +1,153 @@
; Functions ; Includes
(function_definition ((command_name) @include
function_name: (identifier) @function (#eq? @include "import"))
(end) @keyword.function)
(parameter_list (identifier) @parameter)
; Keywords ; Keywords
((identifier) @keyword
(#eq? @keyword "end"))
(function_keyword) @keyword.function
[ [
"return" "arguments"
] @keyword.return "classdef"
"end"
"enumeration"
"events"
"global"
"methods"
"persistent"
"properties"
] @keyword
; Conditionals ; Conditionals
[ (if_statement [ "if" "end" ] @conditional)
"if" (elseif_clause "elseif" @conditional)
"elseif" (else_clause "else" @conditional)
"else" (switch_statement [ "switch" "end" ] @conditional)
"switch" (case_clause "case" @conditional)
"case" (otherwise_clause "otherwise" @conditional)
"otherwise" (break_statement) @conditional
] @conditional
(if_statement (end) @conditional)
(switch_statement (end) @conditional)
; Repeats ; Repeats
[ (for_statement [ "for" "parfor" "end" ] @repeat)
"for" (while_statement [ "while" "end" ] @repeat)
"while" (continue_statement) @repeat
"break"
"continue"
] @repeat
(for_statement (end) @repeat)
(while_statement (end) @repeat)
; Exceptions ; Exceptions
[ (try_statement [ "try" "end" ] @exception)
"try" (catch_clause "catch" @exception)
"catch"
] @exception
(try_statement (end) @exception) ; Variables
(identifier) @variable
; Constants
(events (identifier) @constant)
(attribute (identifier) @constant)
"~" @constant.builtin
; Fields/Properties
(field_expression field: (identifier) @field)
(superclass "." (identifier) @property)
(property_name "." (identifier) @property)
(property name: (identifier) @property)
; Types
(class_definition name: (identifier) @type)
(attributes (identifier) @constant)
(enum . (identifier) @type)
((identifier) @type
(#lua-match? @type "^_*[A-Z][a-zA-Z0-9_]+$"))
; Functions
(function_definition
"function" @keyword.function
name: (identifier) @function
[ "end" "endfunction" ]? @keyword.function)
(function_signature name: (identifier) @function)
(function_call
name: (identifier) @function.call)
(handle_operator (identifier) @function)
(validation_functions (identifier) @function)
(command (command_name) @function.call)
(command_argument) @parameter
(return_statement) @keyword.return
; Parameters
(function_arguments (identifier) @parameter)
; Punctuation ; Punctuation
[ [ ";" "," "." ] @punctuation.delimiter
","
";"
":"
] @punctuation.delimiter
[ "{" "}" ] @punctuation.bracket [ "(" ")" "[" "]" "{" "}" ] @punctuation.bracket
[ "[" "]" ] @punctuation.bracket
[ "(" ")" ] @punctuation.bracket
; Operators ; Operators
[ [
">" "+"
"<" ".+"
"==" "-"
"<=" ".*"
">="
"=<"
"=>"
"~="
"*" "*"
".*" ".*"
"/" "/"
"\\"
"./" "./"
"\\"
".\\"
"^" "^"
".^" ".^"
"+" "'"
".'"
"|"
"&"
"?"
"@"
"<"
"<="
">"
">="
"=="
"~="
"=" "="
"&&" "&&"
"||" "||"
":"
] @operator ] @operator
; Literals ; Literals
(number) @number
(string) @string (string) @string
[ "true" "false" ] @boolean (escape_sequence) @string.escape
(formatting_sequence) @string.special
(number) @number
(boolean) @boolean
; Comments ; Comments
(comment) @comment @spell [ (comment) (line_continuation) ] @comment @spell
; Errors ; Errors

View file

@ -0,0 +1,35 @@
"end" @indent.end @indent.branch
[
(if_statement)
(for_statement)
(while_statement)
(switch_statement)
(try_statement)
(function_definition)
(class_definition)
(enumeration)
(events)
(methods)
(properties)
] @indent.begin
[
"elseif"
"else"
"case"
"otherwise"
"catch"
] @indent.branch
((matrix (row) @indent.align)
(#set! indent.open_delimiter "[")
(#set! indent.close_delimiter "]"))
((cell (row) @indent.align)
(#set! indent.open_delimiter "{")
(#set! indent.close_delimiter "}"))
((parenthesis) @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))
(comment) @indent.auto

20
queries/matlab/locals.scm Normal file
View file

@ -0,0 +1,20 @@
; References
(identifier) @reference
; Definitions
(function_definition
name: (identifier) @definition.function
(function_arguments
(identifier)* @definition.parameter
("," (identifier) @definition.parameter)*)?) @scope
(assignment left: (identifier) @definition.var)
(multioutput_variable (identifier) @definition.var)
(iterator . (identifier) @definition.var)
(lambda (arguments (identifier) @definition.parameter))
(global_operator (identifier) @definition.var)
(persistent_operator (identifier) @definition.var)
(catch_clause (identifier) @definition)