Skip to content

Commit

Permalink
Add support for Matlab classes
Browse files Browse the repository at this point in the history
Recognize the definition of a class, and allow for functions not to be
defined in the first column but to be indented by white space.
  • Loading branch information
andebjor committed Jul 11, 2018
1 parent 5a4b6d0 commit 95fafa3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
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
methods
function [x,y,z] = classfunc1
function x = classfunc2
function classfunc3
end
end
end

function [x,y,z] = func1
function x = func2
function func3
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

0 comments on commit 95fafa3

Please sign in to comment.