@acristoffers/tree-sitter-matlab 1.2.4 → 1.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -23
- package/grammar.js +81 -58
- package/package.json +1 -1
- package/src/grammar.json +523 -304
- package/src/node-types.json +28 -16
- package/src/parser.c +68065 -75419
- package/src/scanner.c +109 -37
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -60,36 +60,22 @@ Given the existence of external method definition, maybe that is even the
|
|
|
60
60
|
correct thing to do, since we don't know if the current file is inside a
|
|
61
61
|
special class folder.
|
|
62
62
|
|
|
63
|
-
# Known problems
|
|
64
|
-
|
|
65
|
-
Newlines, just like whitespaces, are mostly ignored. In the case of spaces, it
|
|
66
|
-
allows `abs( a )` and `abs(a)` to be described by the same, simple rule. In the
|
|
67
|
-
case of newlines, it allows many multiline constructs (like, `if`, `while`,
|
|
68
|
-
`function`) to be expressed the same way.
|
|
69
|
-
|
|
70
|
-
This creates the undesired side-effect that some constructs, which are not
|
|
71
|
-
accepted by MATLAB, are correctly parsed, like:
|
|
72
|
-
|
|
73
|
-
```matlab
|
|
74
|
-
function (
|
|
75
|
-
a
|
|
76
|
-
)
|
|
77
|
-
end
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
This, however, is hard to fix. The assumption that newlines are ignored by
|
|
81
|
-
default is all over the grammar and changing it requires making changes to too
|
|
82
|
-
many rules, which also make them all more complex and fragile. Therefore, this
|
|
83
|
-
change won't be made.
|
|
84
|
-
|
|
85
63
|
# Installation
|
|
86
64
|
|
|
87
65
|
This parser is now the default for the following editors:
|
|
88
66
|
|
|
89
67
|
- Emacs: Through the `tree-sitter-langs` package.
|
|
90
|
-
- Helix: Builtin
|
|
68
|
+
- Helix: Builtin.
|
|
91
69
|
- Neovim: Through the `nvim-treesitter` plugin.
|
|
92
70
|
|
|
71
|
+
# Known issues
|
|
72
|
+
|
|
73
|
+
- There is a conflict between numbers and element-wise operators that will
|
|
74
|
+
cause a wrong parse if there is no space between the number and the operator.
|
|
75
|
+
For example, `1./a` will be interpreted as `1. / a` instead of the correct
|
|
76
|
+
`1 ./ a`. This problem does not happen if there is a space between the number
|
|
77
|
+
and the operator.
|
|
78
|
+
|
|
93
79
|
# Screenshots
|
|
94
80
|
|
|
95
81
|

|
package/grammar.js
CHANGED
|
@@ -44,6 +44,8 @@ module.exports = grammar({
|
|
|
44
44
|
[$._index_row, $.row],
|
|
45
45
|
[$.function_call, $._function_call_with_keywords],
|
|
46
46
|
[$.block, $._functionless_block],
|
|
47
|
+
[$.function_definition, $._function_definition_with_end],
|
|
48
|
+
[$._function_definition_with_end],
|
|
47
49
|
],
|
|
48
50
|
|
|
49
51
|
externals: ($) => [
|
|
@@ -71,9 +73,12 @@ module.exports = grammar({
|
|
|
71
73
|
|
|
72
74
|
rules: {
|
|
73
75
|
source_file: ($) =>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
seq(
|
|
77
|
+
repeat($._end_of_line),
|
|
78
|
+
choice(
|
|
79
|
+
optional(seq($._block, repeat($.function_definition))),
|
|
80
|
+
repeat1($.function_definition),
|
|
81
|
+
),
|
|
77
82
|
),
|
|
78
83
|
|
|
79
84
|
_block: ($) =>
|
|
@@ -235,6 +240,7 @@ module.exports = grammar({
|
|
|
235
240
|
$.postfix_operator,
|
|
236
241
|
$.string,
|
|
237
242
|
$.unary_operator,
|
|
243
|
+
$.not_operator,
|
|
238
244
|
),
|
|
239
245
|
')',
|
|
240
246
|
),
|
|
@@ -261,7 +267,22 @@ module.exports = grammar({
|
|
|
261
267
|
),
|
|
262
268
|
),
|
|
263
269
|
|
|
264
|
-
not_operator: ($) => prec(PREC.not, seq('~',
|
|
270
|
+
not_operator: ($) => prec(PREC.not, seq('~', choice(
|
|
271
|
+
$.cell,
|
|
272
|
+
$.function_call,
|
|
273
|
+
$.handle_operator,
|
|
274
|
+
$.identifier,
|
|
275
|
+
$.matrix,
|
|
276
|
+
$.metaclass_operator,
|
|
277
|
+
$.not_operator,
|
|
278
|
+
$.number,
|
|
279
|
+
$.parenthesis,
|
|
280
|
+
$.postfix_operator,
|
|
281
|
+
$.range,
|
|
282
|
+
$.string,
|
|
283
|
+
$.unary_operator,
|
|
284
|
+
$.field_expression,
|
|
285
|
+
))),
|
|
265
286
|
|
|
266
287
|
metaclass_operator: ($) => prec.left(seq('?', seq($.identifier, repeat(seq('.', $.identifier))))),
|
|
267
288
|
|
|
@@ -344,15 +365,15 @@ module.exports = grammar({
|
|
|
344
365
|
matrix: ($) =>
|
|
345
366
|
seq(
|
|
346
367
|
'[',
|
|
347
|
-
repeat(
|
|
348
|
-
optional(seq($.row, repeat(seq(choice(
|
|
368
|
+
repeat(choice(/[,]*;[ ,;]*/, /[\r\n]/)),
|
|
369
|
+
optional(seq($.row, repeat(seq(choice(/[,]*;[ ,;]*/, /[\r\n]/), optional($.row))))),
|
|
349
370
|
']',
|
|
350
371
|
),
|
|
351
372
|
cell: ($) =>
|
|
352
373
|
seq(
|
|
353
374
|
'{',
|
|
354
|
-
repeat(
|
|
355
|
-
optional(seq($.row, repeat(seq(choice(
|
|
375
|
+
repeat(choice(/[,]*;[ ,;]*/, /[\r\n]/)),
|
|
376
|
+
optional(seq($.row, repeat(seq(choice(/[,]*;[ ,;]*/, /[\r\n]/), optional($.row))))),
|
|
356
377
|
'}',
|
|
357
378
|
),
|
|
358
379
|
|
|
@@ -461,7 +482,7 @@ module.exports = grammar({
|
|
|
461
482
|
alias($._index_unary_operator, $.unary_operator),
|
|
462
483
|
),
|
|
463
484
|
),
|
|
464
|
-
choice("
|
|
485
|
+
choice(alias($._transpose, "'"), alias($._ctranspose, ".'")),
|
|
465
486
|
),
|
|
466
487
|
),
|
|
467
488
|
_index_row: ($) =>
|
|
@@ -705,7 +726,7 @@ module.exports = grammar({
|
|
|
705
726
|
),
|
|
706
727
|
|
|
707
728
|
iterator: ($) => seq($.identifier, '=', $._expression),
|
|
708
|
-
parfor_options: ($) => choice($.number, $.identifier, $.function_call, $.string),
|
|
729
|
+
parfor_options: ($) => choice($.number, $.identifier, $.field_expression, $.function_call, $.string),
|
|
709
730
|
for_statement: ($) =>
|
|
710
731
|
choice(
|
|
711
732
|
seq(
|
|
@@ -786,7 +807,7 @@ module.exports = grammar({
|
|
|
786
807
|
'arguments',
|
|
787
808
|
optional(alias($._argument_attributes, $.attributes)),
|
|
788
809
|
repeat1($._end_of_line),
|
|
789
|
-
repeat(choice($.property,
|
|
810
|
+
repeat(seq(choice($.property, $.class_property), repeat1($._end_of_line))),
|
|
790
811
|
'end',
|
|
791
812
|
optional($._end_of_line),
|
|
792
813
|
)),
|
|
@@ -796,36 +817,39 @@ module.exports = grammar({
|
|
|
796
817
|
function_arguments: ($) =>
|
|
797
818
|
seq('(', field('arguments', optional($._lambda_arguments)), ')'),
|
|
798
819
|
function_definition: ($) =>
|
|
799
|
-
prec.
|
|
820
|
+
prec.dynamic(0, seq(
|
|
800
821
|
'function',
|
|
801
822
|
optional($.function_output),
|
|
802
823
|
optional(choice('get.', 'set.')),
|
|
803
824
|
field('name', choice($.identifier, $.property_name, alias($.end_keyword, $.identifier))),
|
|
804
825
|
optional($.function_arguments),
|
|
805
826
|
$._end_of_line,
|
|
806
|
-
repeat($.arguments_statement),
|
|
807
|
-
repeat($.comment),
|
|
808
|
-
repeat($._end_of_line),
|
|
827
|
+
repeat(seq(repeat(choice($.comment, $._end_of_line)), $.arguments_statement)),
|
|
828
|
+
repeat(choice($.comment, $._end_of_line)),
|
|
809
829
|
optional(alias($._functionless_block, $.block)),
|
|
810
830
|
optional(seq(choice('end', 'endfunction'), optional(';'))),
|
|
811
831
|
)),
|
|
812
832
|
_function_definition_with_end: ($) =>
|
|
813
|
-
prec.
|
|
833
|
+
prec.dynamic(1, seq(
|
|
814
834
|
'function',
|
|
815
835
|
optional($.function_output),
|
|
816
836
|
optional(choice('get.', 'set.')),
|
|
817
837
|
field('name', choice($.identifier, $.property_name, alias($.end_keyword, $.identifier))),
|
|
818
838
|
optional($.function_arguments),
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
839
|
+
optional(
|
|
840
|
+
seq(
|
|
841
|
+
$._end_of_line,
|
|
842
|
+
repeat(seq(repeat(choice($.comment, $._end_of_line)), $.arguments_statement)),
|
|
843
|
+
repeat(choice($.comment, $._end_of_line)),
|
|
844
|
+
optional($.block),
|
|
845
|
+
)
|
|
846
|
+
),
|
|
824
847
|
choice('end', 'endfunction'),
|
|
825
848
|
optional(';'),
|
|
826
849
|
)),
|
|
827
850
|
|
|
828
|
-
|
|
851
|
+
_negated_attribute: ($) => seq("~", $.identifier),
|
|
852
|
+
attribute: ($) => choice(alias($._negated_attribute, $.not_operator), seq($.identifier, optional(seq('=', $._expression)))),
|
|
829
853
|
attributes: ($) =>
|
|
830
854
|
seq('(', $.attribute, repeat(seq(',', $.attribute)), ')'),
|
|
831
855
|
superclasses: ($) =>
|
|
@@ -837,46 +861,44 @@ module.exports = grammar({
|
|
|
837
861
|
default_value: ($) => seq('=', $._expression),
|
|
838
862
|
property_name: ($) =>
|
|
839
863
|
prec.right(
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
optional(seq('.', '*')),
|
|
846
|
-
),
|
|
864
|
+
-1,
|
|
865
|
+
seq(
|
|
866
|
+
$.identifier,
|
|
867
|
+
repeat(seq('.', $.identifier)),
|
|
868
|
+
optional(seq('.', '*')),
|
|
847
869
|
),
|
|
848
870
|
),
|
|
849
871
|
property: ($) =>
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
872
|
+
prec.right(
|
|
873
|
+
choice(
|
|
874
|
+
seq(
|
|
875
|
+
field(
|
|
876
|
+
'name',
|
|
877
|
+
choice($.identifier, $.property_name, $.ignored_argument),
|
|
878
|
+
),
|
|
879
|
+
optional($.dimensions),
|
|
880
|
+
optional(choice($.identifier, $.property_name)),
|
|
881
|
+
optional($.validation_functions),
|
|
882
|
+
optional($.default_value),
|
|
855
883
|
),
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
884
|
+
seq(
|
|
885
|
+
field(
|
|
886
|
+
'name',
|
|
887
|
+
choice($.identifier, $.property_name, $.ignored_argument),
|
|
888
|
+
),
|
|
889
|
+
'@',
|
|
890
|
+
$.identifier,
|
|
891
|
+
alias(optional(choice('vector', 'matrix', 'scalar')), $.identifier),
|
|
892
|
+
optional($.default_value),
|
|
893
|
+
)
|
|
861
894
|
),
|
|
862
|
-
seq(
|
|
863
|
-
field(
|
|
864
|
-
'name',
|
|
865
|
-
choice($.identifier, $.property_name, $.ignored_argument),
|
|
866
|
-
),
|
|
867
|
-
'@',
|
|
868
|
-
$.identifier,
|
|
869
|
-
alias(optional(choice('vector', 'matrix', 'scalar')), $.identifier),
|
|
870
|
-
optional($.default_value),
|
|
871
|
-
repeat1($._end_of_line),
|
|
872
|
-
)
|
|
873
895
|
),
|
|
874
896
|
properties: ($) =>
|
|
875
897
|
seq(
|
|
876
898
|
'properties',
|
|
877
899
|
optional($.attributes),
|
|
878
|
-
|
|
879
|
-
repeat($.property),
|
|
900
|
+
$._end_of_line,
|
|
901
|
+
repeat(choice(seq($.property, $._end_of_line), $._end_of_line, $.comment)),
|
|
880
902
|
'end',
|
|
881
903
|
),
|
|
882
904
|
function_signature: ($) =>
|
|
@@ -890,10 +912,11 @@ module.exports = grammar({
|
|
|
890
912
|
seq(
|
|
891
913
|
'methods',
|
|
892
914
|
optional($.attributes),
|
|
893
|
-
|
|
915
|
+
repeat($._end_of_line),
|
|
894
916
|
repeat(
|
|
895
917
|
seq(
|
|
896
918
|
choice(
|
|
919
|
+
$.comment,
|
|
897
920
|
alias(seq($.function_output, field('name', alias('end', $.identifier)), $.function_arguments), $.function_signature),
|
|
898
921
|
$.function_signature,
|
|
899
922
|
alias($._function_definition_with_end, $.function_definition)),
|
|
@@ -906,7 +929,7 @@ module.exports = grammar({
|
|
|
906
929
|
'events',
|
|
907
930
|
optional($.attributes),
|
|
908
931
|
$._end_of_line,
|
|
909
|
-
repeat(choice(seq($.identifier, $._end_of_line), $._end_of_line)),
|
|
932
|
+
repeat(choice(seq($.identifier, $._end_of_line), $._end_of_line, $.comment)),
|
|
910
933
|
'end',
|
|
911
934
|
),
|
|
912
935
|
enum: ($) =>
|
|
@@ -916,7 +939,7 @@ module.exports = grammar({
|
|
|
916
939
|
'enumeration',
|
|
917
940
|
optional($.attributes),
|
|
918
941
|
$._end_of_line,
|
|
919
|
-
repeat(choice(seq($.enum, $._end_of_line), $._end_of_line)),
|
|
942
|
+
repeat(choice(seq($.enum, $._end_of_line), $._end_of_line, $.comment)),
|
|
920
943
|
'end',
|
|
921
944
|
),
|
|
922
945
|
class_definition: ($) =>
|
|
@@ -926,7 +949,7 @@ module.exports = grammar({
|
|
|
926
949
|
field('name', $.identifier),
|
|
927
950
|
optional($.superclasses),
|
|
928
951
|
$._end_of_line,
|
|
929
|
-
repeat(choice($.properties, $.methods, $.events, $.enumeration,
|
|
952
|
+
repeat(choice($.properties, $.methods, $.events, $.enumeration, $._end_of_line, $.comment)),
|
|
930
953
|
'end',
|
|
931
954
|
),
|
|
932
955
|
|
|
@@ -957,8 +980,8 @@ module.exports = grammar({
|
|
|
957
980
|
|
|
958
981
|
number: ($) => choice(
|
|
959
982
|
/(\d+|\d+\.\d*|\.\d+)([eEdD][+-]?\d+)?[ij]?/,
|
|
960
|
-
/0[xX][\dA-Fa-f]+([
|
|
961
|
-
/0[bB][01]+([
|
|
983
|
+
/0[xX][\dA-Fa-f]+([suSU](8|16|32|64))?/,
|
|
984
|
+
/0[bB][01]+([suSU](8|16|32|64))?/
|
|
962
985
|
),
|
|
963
986
|
|
|
964
987
|
end_keyword: ($) => 'end',
|