Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Matlab classes #1791

Merged
merged 1 commit into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Units/review-needed.r/matlab_test.m.t/expected.tags
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
A input.m /^A = magic(4);$/;" v
R input.m /^R = randn(3,4,5);$/;" v
class1 input.m /^classdef class1 < handle$/;" c
classfunc1 input.m /^ function [x,y,z] = classfunc1$/;" f
classfunc2 input.m /^ function x = classfunc2$/;" f
classfunc3 input.m /^ function classfunc3$/;" f
func1 input.m /^function [x,y,z] = func1 $/;" f
func2 input.m /^function x = func2 $/;" f
func3 input.m /^function func3 $/;" f
9 changes: 9 additions & 0 deletions Units/review-needed.r/matlab_test.m.t/input.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
classdef class1 < handle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question. Here "handle" is the super class of "class1"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is correct. The handle class is actually a special class, changing the semantics of the derived class.

methods
function [x,y,z] = classfunc1
function x = classfunc2
function classfunc3
end
end
end

function [x,y,z] = func1
function x = func2
function func3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update the test case for testing what you wrote:

and allow for functions not to be
defined in the first column but to be indented by white space.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: I added the two missing function types of this kind as class methods.

Expand Down
9 changes: 6 additions & 3 deletions parsers/matlab.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@

static tagRegexTable matlabTagRegexTable [] = {
/* function [x,y,z] = asdf */
{ "^function[ \t]*\\[.*\\][ \t]*=[ \t]*([a-zA-Z0-9_]+)",
{ "^[ \t]*function[ \t]*\\[.*\\][ \t]*=[ \t]*([a-zA-Z0-9_]+)",
"\\1", "f,function", NULL},
/* function x = asdf */
{"^function[ \t]*[a-zA-Z0-9_]+[ \t]*=[ \t]*([a-zA-Z0-9_]+)",
{"^[ \t]*function[ \t]*[a-zA-Z0-9_]+[ \t]*=[ \t]*([a-zA-Z0-9_]+)",
"\\1", "f,function", NULL},
/* function asdf */
{"^function[ \t]*([a-zA-Z0-9_]+)[^=]*$", "\\1",
{"^[ \t]*function[ \t]*([a-zA-Z0-9_]+)[^=]*$", "\\1",
"f,function", NULL},
/* variables */
{"^[ \t]*([a-zA-Z0-9_]+)[ \t]*=[ \t]", "\\1",
"v,variable", NULL},
/* class definitions */
{"^[ \t]*classdef[ \t]*([a-zA-Z0-9_]+)", "\\1",
"c,class", NULL},
};

/*
Expand Down