Contents
- introduction
- example files
- content of function FARGTEST
- FARG run-time output of function FARGTEST
- content of script FARGSCPT
- FARG run-time output of script FARGSCPT
- FARG saving run-time output of function FARG
- FARG run-time output of stock function AMP1DEA
- content of script FARGPART
- FARG run-time output of script FARGPART
- content of erroneous script FARGERRR
- FARG run-time output of erroneous script FARGERRR
- FARG help
introduction
% FARG parses an M-file for FUNCTION tags and extracts their % syntax % these functions/calls are collected % - M = main function % - S = subfunctions % - N = nested functions % - A = anonymous functions % - E = eval class calls % - X = unresolved calls % % formats of the run-time output, which optionally may be saved % in a character string % % MLINT error-free function: % % T = type of function/call % C = McCabe/cyclomatic complexity % % function# | line#: T C syntax % --------------------------------|--|--|--|-------------------- % 1 ____x: + M = main % x ____x: - S = subfunction % x ____x: . N = nested function % x ____x: @ A = anonymous function % x ____x: ! E = eval class call % x ____x: ? X = unresolved call % % function with fatal syntax error(s): % % line#: column# = <offending syntax> % --------------------------------------- % ____x: y = <MLINT error message> % % NOTE % - clicking on the underlined LINE entry opens the % function in the editor at the corresponding line % - whitespaces and continuation statements are removed % for better readability of the function syntax % - EOL markers may be indicated by <;>s in FARG_ANONYMOUS % definitions, which still yield a valid, executable % syntax when copy/pasted into the command window (see demo) % - definitions are indented according to the function % type for easy reading % - current EVAL class calls are eval|evalc|evalin|feval % - FARG_ANONYMOUS functions are extracted from SCRIPTs % - FARG_ANONYMOUS functions are shown in the full context % of their surrounding statement % - if the lex parser encounters fatal errors, it % will stop processing and print a list of the % offending syntax % % see also: mlint, depfun, depdir, which, functions % % because the LINE open syntax is available only in the % command window output, this feature is turned of during % the demonstration by the [-l] option (see help below)
example files
flst={
'fargtest' % test function with ugly syntax
'fargscpt' % test script with ugly syntax
'farg' % the program itself
'amp1dae' % MATLAB stock function in the demo folder
'fargpart' % test script with ANONYMOUS using parentheses
'fargerrr' % test script with syntax errors
};
content of function FARGTEST
dbtype(flst{1},'13:38');
13 % - main function %#ok
14 function [k,varargout ]= fargtest(... %#ok
15 a, b, ... %#ok
16 varargin... %#ok
17 ) %#ok
18 fh1=@(a, b, c )... %#ok
19 a.*b.*c;,,,x=1:10; %#ok
20 x=pi*sind(30);;;,fh2 = {@(x, y) ... %#ok
21 x * y([2 : 3])};x=1:10; %#ok
22 fhx={ %#ok
23 @(x) sind(x) %#ok
24 @(z) cosd(z) %#ok
25 }; %#ok
26 x=fhx{2}(180*ccc); %#ok
27 % - nested functions %#ok
28 function v=... %#ok
29 nest1(... %#ok
30 a) %#ok
31 subfun1;
32 fargtest;
33 end
34 function v=nest2(b) %#ok
35 v=cellfun(@(x) any(x),ccc,'uni',false);
36 vv=nest1(pi); %#ok
37 fhl(2,3,4);
38 end
% NOTE % - various continuation statements % - surrounding of ANONYMOUS functions
FARG run-time output of function FARGTEST
farg(flst{1},'-l');
% -or- farg fargtest -l
%% parsing... F:\usr\matlab\tmp\fex\afarg\old09\fargtest.m
%% done 0.2500 sec
%% MATLAB version : 7.8.0.347 (R2009a)
%% FARG version : 18-Jun-2009 09:41:48
%% run date : 18-Jun-2009 09:41:49
%%
%% FILE : F:\usr\matlab\tmp\fex\afarg\old09\fargtest.m
%% - Pcode :
%% - type : FUNCTION
%% - date : 18-Jun-2009
%% - time : 09:41:48
%% - size : 1241 bytes
%% - LEX tokens : 333
%% - lines : 48
%% - comments : 38 / 79.17 %
%% - empty : 1 / 2.08 %
%% - warnings : 0
%% - complexity : 1 max
%% - calls : 39
%% - stock/user : 6 / unique 4
%% - functions : 18
%% - main : + 1 / recursion 1
%% - subroutines : - 1
%% - nested : . 2
%% - anonymous : @ 7
%% - eval : ! 0
%% - unresolved : ? 6
%%
%% FUNCTIONS
%% #|line : T C syntax
%% ------------------------|--|--|--|----------------------------------------
%% 1| 14: + 1 [k,varargout]=fargtest(a,b,varargin)
%% 2| 18: @ fh1=@(a,b,c) a.*b.*c
%% 3| 20: @ fh2={@(x,y) x*y([2:3])}
%% 4| 23: @ @(x) sind(x)
%% 5| 24: @ @(z) cosd(z)
%% 6| 26: ? ccc [source?]
%% 7| 28: . 1 v=nest1(a)
%% 8| 32: + fargtest
%% 9| 34: . 1 v=nest2(b)
%% 10| 35: @ v=cellfun(@(x) any(x),ccc,'uni',false)
%% 11| 35: ? ccc [source?]
%% 12| 37: ? fhl
%% 13| 39: ? fhl
%% 14| 42: - 1 [ai,bi,varargout]=subfun1(ao,bo,varargin)
%% 15| 44: ? a
%% 16| 44: ? bb
%% 17| 45: @ afun(a,bb)={@(x,y) x.*f(y,y([1,5]))}
%% 18| 46: @ bfun(a([1:4]))=@(x) sscanf(x','%s:%d').'.*10
% NOTE % - file type: FUNCTION % - two headers during run-time, only the second part is saved (see below) % - whitespaces and continuation statements are removed % - indentation according to the function type % - ANONYMOUS (@) functions are shown in their full context
content of script FARGSCPT
dbtype(flst{2},'12:16');
12 c=cellstr('a'),fh(1)=... %#ok
13 cellfun(@(x) sscanf(x','%s:%d'),c,'uni',... %#ok
14 false);clear c; %#ok
15 y=zeros(2,10);fh(2)={{{@(x,y) x.'*... %#ok
16 y(:,[1,2,5:end])}}};disp(y);
FARG run-time output of script FARGSCPT
farg(flst{2},'-l')
%% parsing... F:\usr\matlab\tmp\fex\afarg\old09\fargscpt.m
%% done 0.0310 sec
%% MATLAB version : 7.8.0.347 (R2009a)
%% FARG version : 18-Jun-2009 09:41:48
%% run date : 18-Jun-2009 09:41:49
%%
%% FILE : F:\usr\matlab\tmp\fex\afarg\old09\fargscpt.m
%% - Pcode :
%% - type : SCRIPT
%% - date : 18-Jun-2009
%% - time : 09:41:48
%% - size : 473 bytes
%% - LEX tokens : 112
%% - lines : 16
%% - comments : 14 / 87.50 %
%% - empty : 1 / 6.25 %
%% - warnings : 0
%% - complexity : NaN max
%% - calls : 14
%% - stock/user : 6 / unique 6
%% - functions : 2
%% - main : + 0 / recursion 0
%% - subroutines : - 0
%% - nested : . 0
%% - anonymous : @ 2
%% - eval : ! 0
%% - unresolved : ? 0
%%
%% FUNCTIONS
%% #|line : T C syntax
%% ------------------------|--|--|--|------------------------------------------------
%% 1| 13: @ fh(1)=cellfun(@(x) sscanf(x','%s:%d'),c,'uni',false)
%% 2| 15: @ fh(2)={{{@(x,y) x.'*y(:,[1,2,5:end])}}}
% NOTE % - file type: SCRIPT
FARG saving run-time output of function FARG
% NOTE % - no run-time output: [-s] option % - output is saved in p % p=farg(flst{3},'-s','-l'); % % show content of output (p) % disp(p);
%% MATLAB version : 7.8.0.347 (R2009a)
%% FARG version : 18-Jun-2009 09:41:48
%% run date : 18-Jun-2009 09:41:50
%%
%% FILE : F:\usr\matlab\tmp\fex\afarg\old09\farg.m
%% - Pcode :
%% - type : FUNCTION
%% - date : 18-Jun-2009
%% - time : 09:41:48
%% - size : 32342 bytes
%% - LEX tokens : 10177
%% - lines : 1295
%% - comments : 263 / 20.31 %
%% - empty : 99 / 7.64 %
%% - warnings : 0
%% - complexity : 22 max
%% - calls : 449
%% - stock/user : 202 / unique 65
%% - functions : 28
%% - main : + 1 / recursion 0
%% - subroutines : - 16
%% - nested : . 0
%% - anonymous : @ 11
%% - eval : ! 0
%% - unresolved : ? 0
%%
%% FUNCTIONS
%% #|line : T C syntax
%% -------------------------|--|--|--|---------------------------------------------------------------------------------------------------
%% 1| 153: + 9 [p,pp]=farg(varargin)
%% 2| 201: - 22 [p,par]=FARG_ini_par(magic,fver,varargin)
%% 3| 281: @ par.rexfh=@(x) regexp(x,par.rexmod,'match')
%% 4| 315: @ par.scom=@(x) textscan(x,'%d/%d(%d):%[^:]:%s')
%% 5| 444: - 1 [p,par]=FARG_get_file(p,par)
%% 6| 474: - 7 par=FARG_chk_lint(par)
%% 7| 489: @ fnc=@(x,y,z) sprintf(['%s%5d>',fmt,':%s'],par.bol,x,y,z)
%% 8| 493: @ fnc=@(x,y,z) sprintf(['%s%5d>',fmt,':%s'],par.bol,x,par.wnam,y,y,z)
%% 9| 498: @ par.lint.err=cellfun(@(x,y,z) fnc(x,y,z),num2cell(1:numel(err)),{err.line},{err.message},'uni',false).'
%% 10| 513: @ par.lint.ncyc=cellfun(@(x) sscanf(x,'%d'),par.lint.cyc(:,2))
%% 11| 560: - 6 [p,par]=FARG_get_calls(p,par)
%% 12| 571: @ bx=cellfun(@(x) sscanf(x,'%*2s%d%d%*s'),par.call(ix),'uni',false)
%% 13| 574: @ ex=cellfun(@(x) sscanf(x,'%*2s%d%d%*s'),par.call(find(ix)+1),'uni',false)
%% 14| 612: - 13 [p,par]=FARG_get_class(p,par,mode)
%% 15| 680: - 19 [p,par]=FARG_get_entries(p,par)
%% 16| 785: @ p.s=@(varargin) FARG_show_entries(p,varargin{:})
%% 17| 803: - 8 [p,par]=FARG_chk_entries(p,par)
%% 18| 885: @ p.U.fd(us)=cellfun(@(x) sprintf('%s[source?]',x),p.U.fn(us),'uni',false)
%% 19| 892: - 5 [p,par]=FARG_upd_entries(p,par,fe,ur,uk)
%% 20| 912: - 2 [p,par,sr,ixb]=FARG_add_entries(p,par,sr,fe,ixb)
%% 21| 930: - 7 [p,par]=FARG_set_entries(p,par,s,sr,ixb)
%% 22| 976: @ sd=cellfun(@(a,b) sprintf(fmt,a,b),sf,sd,'uni',false)
%% 23| 991: - 13 p=FARG_get_context(p,par,fe,isclosed)
%% 24| 1052: - 3 ss=FARG_set_context(p,par,fe)
%% 25| 1087: - 6 s=FARG_set_bracket(s)
%% 26| 1126: - 12 [p,par,s]=FARG_set_text(p,par,mode)
%% 27| 1240: - 2 FARG_sdisp(par,txt)
%% 28| 1247: - 8 s=FARG_show_entries(p,varargin)
% NOTE % - the first part of the run-time output is not saved % - each line is preceded by MATLAB comment delimiters % this allows of easy copy/pasting into an other M-file
FARG run-time output of stock function AMP1DEA
farg(flst{4},'-l');
%% parsing... F:\usr\r2009a\toolbox\matlab\demos\amp1dae.m
%% done 0.0310 sec
%% MATLAB version : 7.8.0.347 (R2009a)
%% FARG version : 18-Jun-2009 09:41:48
%% run date : 18-Jun-2009 09:41:51
%%
%% FILE : F:\usr\r2009a\toolbox\matlab\demos\amp1dae.m
%% - Pcode :
%% - type : FUNCTION
%% - date : 21-Jun-2005
%% - time : 15:24:08
%% - size : 2639 bytes
%% - LEX tokens : 554
%% - lines : 88
%% - comments : 34 / 38.64 %
%% - empty : 14 / 15.91 %
%% - warnings : 0
%% - complexity : 1 max
%% - calls : 24
%% - stock/user : 10 / unique 10
%% - functions : 3
%% - main : + 1 / recursion 0
%% - subroutines : - 0
%% - nested : . 1
%% - anonymous : @ 1
%% - eval : ! 0
%% - unresolved : ? 0
%%
%% FUNCTIONS
%% #|line : T C syntax
%% ------------------------|--|--|--|---------------------
%% 1| 1: + 1 amp1dae
%% 2| 31: @ Ue=@(t) 0.4*sin(200*pi*t)
%% 3| 74: . 1 dudt=f(t,u)
content of script FARGPART
dbtype(flst{5},'12:29');
12 a=pi;b=a;c='c';a=...
13 @(x) {...
14 x.a,x.(b).c
15
16 patch(a,b,c),foo(a)
17 cellfun(@(x) x,b,'uni',false),goo(a)
18 };
19 b=@(x) [
20
21
22 x,x
23 x,x
24
25 ];
26 c=...
27 @(x) (...
28 1:x...
29 );
FARG run-time output of script FARGPART
farg(flst{5},'-l');
%% parsing... F:\usr\matlab\tmp\fex\afarg\old09\fargpart.m
%% done 0.0310 sec
%% MATLAB version : 7.8.0.347 (R2009a)
%% FARG version : 18-Jun-2009 09:41:48
%% run date : 18-Jun-2009 09:41:51
%%
%% FILE : F:\usr\matlab\tmp\fex\afarg\old09\fargpart.m
%% - Pcode :
%% - type : SCRIPT
%% - date : 18-Jun-2009
%% - time : 09:41:48
%% - size : 468 bytes
%% - LEX tokens : 125
%% - lines : 29
%% - comments : 10 / 34.48 %
%% - empty : 5 / 17.24 %
%% - warnings : 0
%% - complexity : NaN max
%% - calls : 5
%% - stock/user : 1 / unique 1
%% - functions : 3
%% - main : + 0 / recursion 0
%% - subroutines : - 0
%% - nested : . 0
%% - anonymous : @ 3
%% - eval : ! 0
%% - unresolved : ? 0
%%
%% FUNCTIONS
%% #|line : T C syntax
%% ------------------------|--|--|--|-------------------------------------------------------------------------
%% 1| 13: @ a=@(x) {x.a,x.(b).c;;patch(a,b,c),foo(a);cellfun(@(x)x,b,'uni',false),goo(a)}
%% 2| 19: @ b=@(x) [;;;x,x;x,x]
%% 3| 27: @ c=@(x) (1:x)
% NOTE % - empty lines (EOL) are indicated by <;> % - these yields ugly yet valid constructs % when copy/pasted into the command window b=@(x) [;;;x,x;x,x] %#ok b(10)
b =
@(x)[x,x;x,x]
ans =
10 10
10 10
content of erroneous script FARGERRR
dbtype(flst{6},'12:13');
12 a=_1; %#ok: invalid character <_> 13 b=@(x sind(x); %#ok: parenthesis imbalance around here
FARG run-time output of erroneous script FARGERRR
% NOTE % - if the parser encounters a fatal syntax error, it stops processing % and prints a list of the offending syntax % - the output will be displayed in the command window even if the % no-print [-s] option is selected! % p=farg(flst{6},'-s','-l');
%% parsing... F:\usr\matlab\tmp\fex\afarg\old09\fargerrr.m
%% done 0.0150 sec
%% LEX errors 2
%% ----------------------------------------------------------------
%% line 12: 5 = <_>
%% line 13: 16 = <;>
% NOTE % - the result (p) contains the error message(s) % disp(p);
%% parsing... F:\usr\matlab\tmp\fex\afarg\old09\fargerrr.m
%% done 0.0150 sec
%% LEX errors 2
%% ----------------------------------------------------------------
%% line 12: 5 = <_>
%% line 13: 16 = <;>
FARG help
help farg; % -or- farg
FARG to look up function syntax in an M-file
FARG parses an M-file for FUNCTION tags
and extracts their syntax
these functions/calls are collected
- M = main function
- S = subfunctions
- N = nested functions
- A = anonymous functions
- E = eval class calls
- X = unresolved calls
SYNTAX
-------------------------------------------------------------------------------
E = FARG
returns the current FARG engine structure in E
FARG FNAM OPT1 ... OPTx
P = FARG(FNAM,'OPT1',...,'OPTx')
[P,E] = FARG(...);
INPUT
-------------------------------------------------------------------------------
FNAM : name of an M-file or P-file including a full or partial path
- a P-file must have a corresponding M-file or an error is
generated
OPT description
----------------------------------------------------------------
-h : show file synopsis only
-e : show eval class calls
-w : show warnings
-l : do NOT make LINE entries open the file (see below)
- use this option if your output is NOT directed
to the command window, e.g., a html file
- a copy/paste from the command window will remove
the lineopen syntax automatically
-s : do NOT print run-time output
- this option is turned off automatically if
the file has fatal syntax errors
-d : save lex parser engine
OUTPUT
-------------------------------------------------------------------------------
E : FARG engine parameters
P : runtime output saved in a character string in this format
MLINT error-free function:
T = type of function/call
C = McCabe/cyclomatic complexity
function# | line#: T C syntax
--------------------------------|--|--|--|--------------------
1 ____x: + M = main
x ____x: - S = subfunction
x ____x: . N = nested function
x ____x: @ A = anonymous function
x ____x: ! E = eval class call
x ____x: ? X = unresolved call
function with fatal syntax error(s):
line#: column# = <offending syntax>
---------------------------------------
____x: y = <MLINT error message>
NOTE
-------------------------------------------------------------------------------
- clicking on the underlined LINE entry opens the
function in the editor at the corresponding line
- whitespaces and continuation statements are removed
for better readability of the function syntax
- EOL markers may be indicated by <;>s in FARG_ANONYMOUS
definitions, which still yield a valid, executable
syntax when copy/pasted into the command window (see demo)
- definitions are indented according to the function
type for easy reading
- current EVAL class calls are eval|evalc|evalin|feval
- FARG_ANONYMOUS functions are extracted from SCRIPTs
- FARG_ANONYMOUS functions are shown in the full context
of their surrounding statement
- if the lex parser encounters fatal errors, it
will stop processing and print a list of the
offending syntax
see also: mlint, depfun, depdir, which, functions
EXAMPLE
-------------------------------------------------------------------------------
farg amp1dae % a MATLAB stock function from the demo folder
% MATLAB version : 7.8.0.347 (R2009a)
% FARG version : 18-Jun-2009 09:41:48
% run date : 18-Jun-2009 09:41:48
%
% FILE : F:\usr\r2009a\toolbox\matlab\demos\amp1dae.m
% - Pcode :
% - type : FUNCTION
% - date : 21-Jun-2005
% - time : 15:24:08
% - size : 2639 bytes
% - LEX tokens : 554
% - lines : 88
% - comments : 34 / 38.64 %
% - empty : 14 / 15.91 %
% - warnings : 0
% - complexity : 1 max
% - calls : 24
% - stock/user : 10 / unique 10
% - functions : 3
% - main : + 1 / recursion 0
% - subroutines : - 0
% - nested : . 1
% - anonymous : @ 1
% - eval : ! 0
% - unresolved : ? 0
%
% FUNCTIONS
% #|line : T C syntax
% ------------------------|--|--|--|---------------------
% 1| 1: + 1 amp1dae
% 2| 31: @ Ue=@(t) 0.4*sin(200*pi*t)
% 3| 74: . 1 dudt=f(t,u)