on master help sign in
Replace MATLAB grammar (#7388)
commit2c5288dafb88ae2a12d3589b79a525932f48b6b3 authorÁlan Crístoffer <acristoffers@startmail.com> dateFri 23 Jun 2023, 00:19 (3 years ago) parent842518c
9 files changed+213−78
book/src/generated/lang-support.md+1−1 languages.toml+1−1 runtime/queries/matlab/context.scm+41 runtime/queries/matlab/folds.scm+11 runtime/queries/matlab/highlights.scm+106−76 runtime/queries/matlab/indents.scm+23 runtime/queries/matlab/injections.scm+2 runtime/queries/matlab/locals.scm+19 runtime/queries/matlab/textobjects.scm+9
book/src/generated/lang-support.md+1−1
@@ -88,7 +88,7 @@
8888| markdoc | ✓ | | | `markdoc-ls` |
8989| markdown | ✓ | | | `marksman` |
9090| markdown.inline | ✓ | | | |
91−| matlab | ✓ | | | |
91+| matlab | ✓ | ✓ | ✓ | |
9292| mermaid | ✓ | | | |
9393| meson | ✓ | | ✓ | |
9494| mint | | | | `mint` |
languages.toml+1−1
@@ -2285,7 +2285,7 @@ indent = { tab-width = 2, unit = " " }
22852285
22862286[[grammar]]
22872287name = "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" }
22892289
22902290[[language]]
22912291name = "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
22
3−function_keyword: (function_keyword) @keyword.function
3+(events (identifier) @constant)
4+(attribute (identifier) @constant)
45
5−(function_definition
6−function_name: (identifier) @function
7−(end) @function)
6+"~" @constant.builtin
87
9−(parameter_list (identifier) @variable.parameter)
8+; Fields/Properties
109
11−[
12− "if"
13− "elseif"
14− "else"
15− "switch"
16− "case"
17− "otherwise"
18−] @keyword.control.conditional
10+(superclass "." (identifier) @variable.other.member)
11+(property_name "." (identifier) @variable.other.member)
12+(property name: (identifier) @variable.other.member)
1913
20−(if_statement (end) @keyword.control.conditional)
21−(switch_statement (end) @keyword.control.conditional)
14+; Types
2215
23−["for" "while"] @keyword.control.repeat
24−(for_statement (end) @keyword.control.repeat)
25−(while_statement (end) @keyword.control.repeat)
16+(class_definition name: (identifier) @keyword.storage.type)
17+(attributes (identifier) @constant)
18+(enum . (identifier) @type.enum.variant)
2619
27−["try" "catch"] @keyword.control.exception
28−(try_statement (end) @keyword.control.exception)
20+; Functions
2921
30−(function_definition end: (end) @keyword)
22+(function_definition
23+ "function" @keyword.function
24+ name: (identifier) @function
25+ [ "end" "endfunction" ]? @keyword.function)
3126
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
3334
34−(
35−(identifier) @constant.builtin
36−(#any-of? @constant.builtin "true" "false")
37−)
35+; Assignments
3836
39−(
40− (identifier) @constant.builtin
41− (#eq? @constant.builtin "end")
42−)
37+(assignment left: (_) @variable)
38+(multioutput_variable (_) @variable)
4339
44−;; Punctuations
40+; Parameters
4541
46−[";" ","] @punctuation.special
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)
42+(function_arguments (identifier) @variable.parameter)
5343
54−; ;; Brackets
44+; Operators
5545
5646[
57− "("
58− ")"
59− "["
60− "]"
61− "{"
62− "}"
63−] @punctuation.bracket
64−
65−;; Operators
66−"=" @operator
67−(operation [ ">"
68− "<"
69− "=="
70− "<="
71− ">="
72− "=<"
73− "=>"
74− "~="
75− "*"
76− ".*"
77− "/"
78− "\\"
79− "./"
80− "^"
81− ".^"
82− "+"] @operator)
83−
84−;; boolean operator
85−[
86− "&&"
87− "||"
47+ "+"
48+ ".+"
49+ "-"
50+ ".*"
51+ "*"
52+ ".*"
53+ "/"
54+ "./"
55+ "\\"
56+ ".\\"
57+ "^"
58+ ".^"
59+ "'"
60+ ".'"
61+ "|"
62+ "&"
63+ "?"
64+ "@"
65+ "<"
66+ "<="
67+ ">"
68+ ">="
69+ "=="
70+ "~="
71+ "="
72+ "&&"
73+ "||"
74+ ":"
8875] @operator
8976
90−;; Number
91−(number) @constant.numeric
77+; Conditionals
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
9294
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
94107(string) @string
108+(number) @constant.numeric.float
109+(boolean) @constant.builtin.boolean
95110
96−;; Comment
97−(comment) @comment
111+; Comments
112+
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