From 1e95d73f6f480290de12351996d57f1895ca378d Mon Sep 17 00:00:00 2001 From: Anton Edvinovich Pozharskiy Date: Thu, 18 Jul 2024 18:18:10 +0200 Subject: [PATCH 1/4] parse metaclass correctly --- Matlab.tmbundle/Syntaxes/MATLAB.tmLanguage | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Matlab.tmbundle/Syntaxes/MATLAB.tmLanguage b/Matlab.tmbundle/Syntaxes/MATLAB.tmLanguage index 3026c3f..5f11e77 100644 --- a/Matlab.tmbundle/Syntaxes/MATLAB.tmLanguage +++ b/Matlab.tmbundle/Syntaxes/MATLAB.tmLanguage @@ -114,6 +114,10 @@ include #curly_brackets + + include + #metaclass_literal + rules_after_command_dual @@ -2992,7 +2996,7 @@ name variable.other.readwrite.matlab match - (?<![a-zA-Z0-9_]|\.)[a-zA-Z][a-zA-Z0-9_]*(?![a-zA-Z0-9_]|(?:\(|\{|\.\()) + (?<![a-zA-Z0-9_]|\.|\?)[a-zA-Z][a-zA-Z0-9_]*(?![a-zA-Z0-9_]|(?:\(|\{|\.\()) property_access @@ -3003,6 +3007,32 @@ match \. + metaclass_literal + + comment + Accessing a metaclass via the ? operator + name + meta.metaclass.matlab + begin + (?<=\?)(?=[a-zA-Z]) + end + (?<=[a-zA-Z0-9_])(?![a-zA-Z0-9_]|\.|\(|{) + patterns + + + name + entity.other.class.matlab + match + (?<=[.\?])[a-zA-Z][a-zA-Z0-9_]*(?![a-zA-Z0-9_.]) + + + name + entity.name.namespace.matlab + match + [a-zA-Z][a-zA-Z0-9_]* + + + From 4278a23da770899a809da7dbec02eb73e7790fb9 Mon Sep 17 00:00:00 2001 From: Anton Edvinovich Pozharskiy Date: Thu, 18 Jul 2024 18:22:41 +0200 Subject: [PATCH 2/4] convert classdef to allow for metaclass on rhs of assign --- Matlab.tmbundle/Syntaxes/MATLAB.tmLanguage | 43 +++++----------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/Matlab.tmbundle/Syntaxes/MATLAB.tmLanguage b/Matlab.tmbundle/Syntaxes/MATLAB.tmLanguage index 5f11e77..a116e88 100644 --- a/Matlab.tmbundle/Syntaxes/MATLAB.tmLanguage +++ b/Matlab.tmbundle/Syntaxes/MATLAB.tmLanguage @@ -831,41 +831,16 @@ true|false + comment + Metadata query for class properties name - meta.metaclass.matlab - begin - (\?) - beginCaptures - - 1 - - name - keyword.operator.other.question.matlab - - - end - (?=\)|,) - patterns - - - name - entity.other.class.matlab - match - (?<=[\s.<])[a-zA-Z][a-zA-Z0-9_]*(?=\s|,|\)) - - - name - entity.name.namespace.matlab - match - [a-zA-Z][a-zA-Z0-9_]* - - - name - punctuation.accessor.dot.matlab - match - \. - - + keyword.operator.other.question.matlab + match + (?<!\w)\?(?=\w) + + + include + #metaclass_literal include From 9772a5a36bdb94ab79b81157ff005a78950304eb Mon Sep 17 00:00:00 2001 From: Anton Edvinovich Pozharskiy Date: Fri, 19 Jul 2024 10:59:18 +0200 Subject: [PATCH 3/4] add unit test --- test/t89MetaclassLiterals.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/t89MetaclassLiterals.m diff --git a/test/t89MetaclassLiterals.m b/test/t89MetaclassLiterals.m new file mode 100644 index 0000000..c597d57 --- /dev/null +++ b/test/t89MetaclassLiterals.m @@ -0,0 +1,17 @@ +% SYNTAX TEST "source.matlab" "Property validation: https://github.com/mathworks/MATLAB-Language-grammar/issues/89" +classdef (AllowedSubclasses = {?SubClass1,?namespace1.SubClass2}) SuperClass +% ^^^^^^^^^ meta.metaclass.matlab entity.other.class.matlab +% ^^^^^^^^^^^^^^^^^^^^ meta.metaclass.matlab +% ^^^^^^^^^^ entity.name.namespace.matlab +% ^^^^^^^^^ entity.other.class.matlab + methods + function foo() + x = ?namespace2.cls +% ^^^^^^^^^^^^^^ meta.metaclass.matlab +% ^^^^^^^^^^ entity.name.namespace.matlab +% ^^^ entity.other.class.matlab + y = ?MyClass +% ^^^^^^^ meta.metaclass.matlab entity.other.class.matlab + end + end +end From 5f142da38f1bc24113fb6ab80a07948f3eb451ab Mon Sep 17 00:00:00 2001 From: Anton Edvinovich Pozharskiy Date: Mon, 22 Jul 2024 09:46:05 +0200 Subject: [PATCH 4/4] fix name in test --- test/t89MetaclassLiterals.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/t89MetaclassLiterals.m b/test/t89MetaclassLiterals.m index c597d57..be88c75 100644 --- a/test/t89MetaclassLiterals.m +++ b/test/t89MetaclassLiterals.m @@ -1,4 +1,4 @@ -% SYNTAX TEST "source.matlab" "Property validation: https://github.com/mathworks/MATLAB-Language-grammar/issues/89" +% SYNTAX TEST "source.matlab" "Metaclasses: https://github.com/mathworks/MATLAB-Language-grammar/issues/89" classdef (AllowedSubclasses = {?SubClass1,?namespace1.SubClass2}) SuperClass % ^^^^^^^^^ meta.metaclass.matlab entity.other.class.matlab % ^^^^^^^^^^^^^^^^^^^^ meta.metaclass.matlab