on master help sign in
Replace MATLAB grammar (#7388)
2c5288dÁlan Crístoffer
book/src/generated/lang-support.md+1−1
@@ -88,7 +88,7 @@
88| markdoc | ✓ | | | `markdoc-ls` |
88| markdoc | ✓ | | | `markdoc-ls` |
89| markdown | ✓ | | | `marksman` |
89| markdown | ✓ | | | `marksman` |
90| markdown.inline | ✓ | | | |
90| markdown.inline | ✓ | | | |
91−| matlab | ✓ | | | |
91+| matlab | ✓ | ✓ | ✓ | |
92| mermaid | ✓ | | | |
92| mermaid | ✓ | | | |
93| meson | ✓ | | ✓ | |
93| meson | ✓ | | ✓ | |
94| mint | | | | `mint` |
94| mint | | | | `mint` |
languages.toml+1−1
@@ -2285,7 +2285,7 @@ indent = { tab-width = 2, unit = " " }
2285
2285
2286[[grammar]]
2286[[grammar]]
2287name = "matlab"
2287name = "matlab"
2288−source = { git = "https://github.com/mstanciu552/tree-sitter-matlab", rev = "2d5d3d5193718a86477d4335aba5b34e79147326" }
2288+source = { git = "https://github.com/acristoffers/tree-sitter-matlab", rev = "5a047c1572792ae943b51af7cf9307097b2fcce0" }
2289
2289
2290[[language]]
2290[[language]]
2291name = "ponylang"
2291name = "ponylang"
runtime/queries/matlab/context.scmnew file+41
@@ -0,0 +1,41 @@
1+(function_definition
2+ (block (_) @context.end)
3+) @context
4+
5+(while_statement
6+ (block (_) @context.end)
7+) @context
8+
9+(for_statement
10+ (block (_) @context.end)
11+) @context
12+
13+(if_statement
14+ (block (_) @context.end)
15+) @context
16+
17+(elseif_clause
18+ (block (_) @context.end)
19+) @context
20+
21+(else_clause
22+ (block (_) @context.end)
23+) @context
24+
25+(switch_statement) @context
26+
27+(case_clause
28+ (block (_) @context.end)
29+) @context
30+
31+(otherwise_clause
32+ (block (_) @context.end)
33+) @context
34+
35+(try_statement
36+ "try"
37+ (block (_) @context.end) @context
38+ "end")
39+(catch_clause
40+ "catch"
41+ (block (_) @context.end) @context)
runtime/queries/matlab/folds.scmnew file+11
@@ -0,0 +1,11 @@
1+[(if_statement)
2+ (for_statement)
3+ (while_statement)
4+ (switch_statement)
5+ (try_statement)
6+ (function_definition)
7+ (class_definition)
8+ (enumeration)
9+ (events)
10+ (methods)
11+ (properties)] @fold
runtime/queries/matlab/highlights.scm+106−76
@@ -1,97 +1,127 @@
1− ; highlights.scm
1+; Constants
2
2
3−function_keyword: (function_keyword) @keyword.function
3+(events (identifier) @constant)
4+(attribute (identifier) @constant)
4
5
5−(function_definition
6+"~" @constant.builtin
6−function_name: (identifier) @function
7−(end) @function)
8
7
9−(parameter_list (identifier) @variable.parameter)
8+; Fields/Properties
10
9
11−[
10+(superclass "." (identifier) @variable.other.member)
12− "if"
11+(property_name "." (identifier) @variable.other.member)
13− "elseif"
12+(property name: (identifier) @variable.other.member)
14− "else"
15− "switch"
16− "case"
17− "otherwise"
18−] @keyword.control.conditional
19
13
20−(if_statement (end) @keyword.control.conditional)
14+; Types
21−(switch_statement (end) @keyword.control.conditional)
22
15
23−["for" "while"] @keyword.control.repeat
16+(class_definition name: (identifier) @keyword.storage.type)
24−(for_statement (end) @keyword.control.repeat)
17+(attributes (identifier) @constant)
25−(while_statement (end) @keyword.control.repeat)
18+(enum . (identifier) @type.enum.variant)
26
19
27−["try" "catch"] @keyword.control.exception
20+; Functions
28−(try_statement (end) @keyword.control.exception)
29
21
30−(function_definition end: (end) @keyword)
22+(function_definition
23+ "function" @keyword.function
24+ name: (identifier) @function
25+ [ "end" "endfunction" ]? @keyword.function)
31
26
32−["return" "break" "continue"] @keyword.return
27+(function_signature name: (identifier) @function)
28+(function_call name: (identifier) @function)
29+(handle_operator (identifier) @function)
30+(validation_functions (identifier) @function)
31+(command (command_name) @function.macro)
32+(command_argument) @string
33+(return_statement) @keyword.control.return
33
34
34−(
35+; Assignments
35−(identifier) @constant.builtin
36−(#any-of? @constant.builtin "true" "false")
37−)
38
36
39−(
37+(assignment left: (_) @variable)
40− (identifier) @constant.builtin
38+(multioutput_variable (_) @variable)
41− (#eq? @constant.builtin "end")
42−)
43
39
44−;; Punctuations
40+; Parameters
45
41
46−[";" ","] @punctuation.special
42+(function_arguments (identifier) @variable.parameter)
47−(argument_list "," @punctuation.delimiter)
48−(vector_definition ["," ";"] @punctuation.delimiter)
49−(cell_definition ["," ";"] @punctuation.delimiter)
50−":" @punctuation.delimiter
51−(parameter_list "," @punctuation.delimiter)
52−(return_value "," @punctuation.delimiter)
53
43
54−; ;; Brackets
44+; Operators
55
45
56[
46[
47+ "+"
48+ ".+"
49+ "-"
50+ ".*"
51+ "*"
52+ ".*"
53+ "/"
57− "("
54+ "./"
58− ")"
55+ "\\"
59− "["
56+ ".\\"
60− "]"
57+ "^"
61− "{"
58+ ".^"
62− "}"
59+ "'"
63−] @punctuation.bracket
60+ ".'"
64−
61+ "|"
65−;; Operators
62+ "&"
66−"=" @operator
63+ "?"
67−(operation [ ">"
64+ "@"
68− "<"
65+ "<"
69− "=="
70− "<="
66+ "<="
67+ ">"
71− ">="
68+ ">="
72− "=<"
73− "=>"
69+ "=="
74− "~="
70+ "~="
75− "*"
71+ "="
76− ".*"
77− "/"
78− "\\"
79− "./"
80− "^"
81− ".^"
82− "+"] @operator)
83−
84−;; boolean operator
85−[
86− "&&"
72+ "&&"
87− "||"
73+ "||"
74+ ":"
88] @operator
75] @operator
89
76
90−;; Number
77+; Conditionals
91−(number) @constant.numeric
78+
79+(if_statement [ "if" "end" ] @keyword.control.conditional)
80+(elseif_clause "elseif" @keyword.control.conditional)
81+(else_clause "else" @keyword.control.conditional)
82+(switch_statement [ "switch" "end" ] @keyword.control.conditional)
83+(case_clause "case" @keyword.control.conditional)
84+(otherwise_clause "otherwise" @keyword.control.conditional)
85+(break_statement) @keyword.control.conditional
86+
87+; Repeats
88+
89+(for_statement [ "for" "parfor" "end" ] @keyword.control.repeat)
90+(while_statement [ "while" "end" ] @keyword.control.repeat)
91+(continue_statement) @keyword.control.repeat
92+
93+; Exceptions
92
94
93−;; String
95+(try_statement [ "try" "end" ] @keyword.control.exception)
96+(catch_clause "catch" @keyword.control.exception)
97+
98+; Punctuation
99+
100+[ ";" "," "." ] @punctuation.delimiter
101+[ "(" ")" "[" "]" "{" "}" ] @punctuation.bracket
102+
103+; Literals
104+
105+(escape_sequence) @constant.character.escape
106+(formatting_sequence) @constant.character.escape
94(string) @string
107(string) @string
108+(number) @constant.numeric.float
109+(boolean) @constant.builtin.boolean
95
110
96−;; Comment
111+; Comments
112+
97−(comment) @comment
113+[ (comment) (line_continuation) ] @comment.line
114+
115+; Keywords
116+
117+"classdef" @keyword.storage.type
118+[
119+ "arguments"
120+ "end"
121+ "enumeration"
122+ "events"
123+ "global"
124+ "methods"
125+ "persistent"
126+ "properties"
127+] @keyword
runtime/queries/matlab/indents.scmnew file+23
@@ -0,0 +1,23 @@
1+[
2+ (if_statement)
3+ (for_statement)
4+ (while_statement)
5+ (switch_statement)
6+ (try_statement)
7+ (function_definition)
8+ (class_definition)
9+ (enumeration)
10+ (events)
11+ (methods)
12+ (properties)
13+] @indent
14+
15+[
16+ (elseif_clause)
17+ (else_clause)
18+ (case_clause)
19+ (otherwise_clause)
20+ (catch_clause)
21+] @indent @extend
22+
23+[ "end" ] @outdent
runtime/queries/matlab/injections.scmnew file+2
@@ -0,0 +1,2 @@
1+((comment) @injection.content
2+ (#set! injection.language "comment"))
runtime/queries/matlab/locals.scmnew file+19
@@ -0,0 +1,19 @@
1+(function_definition name: (identifier) @local.definition ?) @local.scope
2+(function_arguments (identifier)* @local.definition)
3+
4+(lambda (arguments (identifier) @local.definition)) @local.scope
5+
6+(assignment left: ((function_call
7+ name: (identifier) @local.definition)))
8+(assignment left: ((field_expression . [(function_call
9+ name: (identifier) @local.definition)
10+ (identifier) @local.definition])))
11+(assignment left: (_) @local.definition)
12+(assignment (multioutput_variable (_) @local.definition))
13+
14+(iterator . (identifier) @local.definition)
15+(global_operator (identifier) @local.definition)
16+(persistent_operator (identifier) @local.definition)
17+(catch_clause (identifier) @local.definition)
18+
19+(identifier) @local.reference
runtime/queries/matlab/textobjects.scmnew file+9
@@ -0,0 +1,9 @@
1+(arguments ((_) @parameter.inside . ","? @parameter.around) @parameter.around)
2+(function_arguments ((_) @parameter.inside . ","? @parameter.around) @parameter.around)
3+
4+(lambda expression: (_) @function.inside) @function.around
5+(function_definition (block) @function.inside) @function.around
6+
7+(class_definition) @class.inside @class.around
8+
9+(comment) @comment.inside @comment.around