Another input parser, very easy to use
Most recent version can probably be found at gitlab: https://gitlab.com/tommsch/m
Features:
- parsing of:
- flags: check which flag of a set of flags is given (see Note (A) )
- name-value pairs: incl. support of alias names, position independent
- key-words: for simple arguments taking only boolean values
- input checks
- set/conditionally-set/read options
- help text generation
- check for unkown options
- passing of unkown options to other parsers
- fully documented
- no splitting of parsing informations between place-of-definition and place-of-parsing
Note:
(A) *** This type of parsing is, to my knowledge, only possible with this parsing function `parsem()` and with `ltfatarghelper()`, the latter part of the LTFAT library, available at github. In particular, Matlabs inputParser also does not support this
(B) Roughly 2x slower than Matlabs inputParser
Example:
varargin = {'abc', 'tommsch',4, 'opt2'};
[ val ] = parsem( 'tommsch', varargin, 2 );
% yields: val=4;
varargin = {'abc', 'tommsch',4, 'opt2'};
[ val ] = parsem( 'tommsch', varargin, 2, 'expect',{0,1,2} );
% yields: val=4;
% and a warning that 'tommsch' only wants values 0, 1 or 2.
varargin = {'abc', 'tommsch',4, 'opt2'};
[val,arg] = parsem( 'Olga', varargin );
% yields: val=false; arg={'abc', 'tommsch',4, 'opt2'},
% Since 'Olga' was not given, val is set to false
% Output argument arg contains all so-far unparsed parts of varargin
varargin = {'abc', 'tommsch',4, 'opt2'};
[val,arg,cc] = parsem( {'opt1','opt2','opt3'}, varargin );
%yields: val=1, cc='opt2', arg={'abc', 'tommsch',4},
% val indicates that one of the options 'op1','opt2','opt3' has been found
% in cc it is stored which option was passed exactly
More options are available.
If you like my parser, please let me know,
Furthermore, please report any bugs you found.
引用
tommsch (2024). parsem (https://www.mathworks.com/matlabcentral/fileexchange/83293-parsem), MATLAB Central File Exchange. に取得済み.
MATLAB リリースの互換性
プラットフォームの互換性
Windows macOS Linuxタグ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!