From: <car...@us...> - 2012-05-10 11:24:41
|
Revision: 10398 http://octave.svn.sourceforge.net/octave/?rev=10398&view=rev Author: carandraug Date: 2012-05-10 11:24:35 +0000 (Thu, 10 May 2012) Log Message: ----------- inputParser/addSwitch: check for correct number of arguments Modified Paths: -------------- trunk/octave-forge/main/general/inst/@inputParser/subsref.m Modified: trunk/octave-forge/main/general/inst/@inputParser/subsref.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-10 11:13:09 UTC (rev 10397) +++ trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-10 11:24:35 UTC (rev 10398) @@ -217,8 +217,12 @@ endif def = false; case {'addSwitch'} - val = def_val; - def = false; + if ( numel (args) == 0 ) + val = def_val; + def = false; + else + print_usage(func); + endif otherwise error ("invalid index for reference of class %s", class (inPar) ); endswitch This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-05-10 18:55:49
|
Revision: 10403 http://octave.svn.sourceforge.net/octave/?rev=10403&view=rev Author: carandraug Date: 2012-05-10 18:55:43 +0000 (Thu, 10 May 2012) Log Message: ----------- inputParser: give better error message when skipping Optional for finding a string that does not validate but it was still not a ParamValue key Modified Paths: -------------- trunk/octave-forge/main/general/inst/@inputParser/subsref.m Modified: trunk/octave-forge/main/general/inst/@inputParser/subsref.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-10 15:00:14 UTC (rev 10402) +++ trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-10 18:55:43 UTC (rev 10403) @@ -121,7 +121,6 @@ error("%sinvalid value for parameter '%s'", inPar.FunctionName, name); endif else - inPar.Results.(name) = value; endif endfor @@ -159,6 +158,9 @@ method = "Switch"; else ## then it must be a ParamValue, shift its value + if (numel (args) < 1) + error ("%sno value found for Parameter '%s'", inPar.FunctionName, key); + endif [value, args] = shift (args); method = "ParamValue"; endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-05-14 07:19:14
|
Revision: 10431 http://octave.svn.sourceforge.net/octave/?rev=10431&view=rev Author: carandraug Date: 2012-05-14 07:19:05 +0000 (Mon, 14 May 2012) Log Message: ----------- inpuParser: check for correct call to parse before starting it to avoid weird errors and print_usage Modified Paths: -------------- trunk/octave-forge/main/general/inst/@inputParser/subsref.m Modified: trunk/octave-forge/main/general/inst/@inputParser/subsref.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-14 07:10:59 UTC (rev 10430) +++ trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-14 07:19:05 UTC (rev 10431) @@ -62,17 +62,17 @@ ## ParamValue mixed with Switch. Any other order makes no sense function inPar = parse_args (inPar, idx) - ## make copy of ordered list of Parameters to keep the original intact and readable - inPar.copy = inPar.Parameters; - - ## this makes it easier to read but may be memory instensive - args = idx(2).subs; - ## syntax is inPar.parse (arguments) if ( numel(idx) != 2 || idx(2).type != '()' ) print_usage ("@inputParser/parse"); endif + ## this makes it easier to read but may be memory instensive + args = idx(2).subs; + + ## make copy of ordered list of Parameters to keep the original intact and readable + inPar.copy = inPar.Parameters; + if ( numel (fieldnames (inPar.Required)) > numel (args) ) error("%sNot enough arguments", inPar.FunctionName); endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-05-14 07:35:51
|
Revision: 10432 http://octave.svn.sourceforge.net/octave/?rev=10432&view=rev Author: carandraug Date: 2012-05-14 07:35:40 +0000 (Mon, 14 May 2012) Log Message: ----------- inputParser: add note about small bug that needs to be fixed Modified Paths: -------------- trunk/octave-forge/main/general/inst/@inputParser/subsref.m Modified: trunk/octave-forge/main/general/inst/@inputParser/subsref.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-14 07:19:05 UTC (rev 10431) +++ trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-14 07:35:40 UTC (rev 10432) @@ -44,6 +44,12 @@ error ("invalid index for reference of class %s", class (inPar) ); endswitch + ## TODO we should make inPar an object of the inputParser class again. At + ## least after running parse it becomes just a structure again. While that is + ## bad, at least allows for easy access to the Results and Unmatched fields + ## without extra coding. +# inPar = class (inPar, 'inputParser'); + endfunction function out = retrieve_results (inPar, idx) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-05-14 08:03:53
|
Revision: 10433 http://octave.svn.sourceforge.net/octave/?rev=10433&view=rev Author: carandraug Date: 2012-05-14 08:03:43 +0000 (Mon, 14 May 2012) Log Message: ----------- inputparser: deal correctly with unmatched parameters Modified Paths: -------------- trunk/octave-forge/main/general/inst/@inputParser/subsref.m Modified: trunk/octave-forge/main/general/inst/@inputParser/subsref.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-14 07:35:40 UTC (rev 10432) +++ trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-14 08:03:43 UTC (rev 10433) @@ -89,7 +89,7 @@ [name, inPar.copy] = shift (inPar.copy); [value, args] = shift (args); if ( !feval (inPar.Required.(name).validator, value) ) - error("%sinvalid value for parameter '%s'", inPar.FunctionName, name); + error("%sargument '%s' failed validation %s", inPar.FunctionName, name, func2str (inPar.Required.(name).validator)); endif inPar.Results.(name) = value; endfor @@ -163,16 +163,16 @@ value = true; method = "Switch"; else - ## then it must be a ParamValue, shift its value + ## then it must be a ParamValue (even if unmatched), shift its value if (numel (args) < 1) - error ("%sno value found for Parameter '%s'", inPar.FunctionName, key); + error ("%sparameter '%s' does not have a value", inPar.FunctionName, key); endif [value, args] = shift (args); method = "ParamValue"; endif - ## index == 0 means no match so either return error or move them into 'Unmatched' - if ( index != 0 ) + ## empty index means no match so either return error or move them into 'Unmatched' + if (!isempty (index)) [name, inPar.copy] = shift (inPar.copy, index); if ( !feval (inPar.(method).(name).validator, value)) error("%sinvalid value for parameter '%s'", inPar.FunctionName, key); @@ -180,11 +180,11 @@ ## we use the name shifted from 'copy' instead of the key from 'args' in case ## the key is in the wrong case inPar.Results.(name) = value; - elseif ( index == 0 && inPar.KeepUnmatched ) + elseif (isempty (index) && inPar.KeepUnmatched ) inPar.Unmatched.(key) = value; i = i - 1; # this time didn't count, go back one - elseif ( index == 0 && !inPar.KeepUnmatched ) - error("%sfound unmatched parameter '%s'", inPar.FunctionName, name); + else + error ("%sargument '%s' did not match any valid parameter of the parser", inPar.FunctionName, key); endif endfor This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-05-14 08:18:01
|
Revision: 10434 http://octave.svn.sourceforge.net/octave/?rev=10434&view=rev Author: carandraug Date: 2012-05-14 08:17:51 +0000 (Mon, 14 May 2012) Log Message: ----------- inputParser: mention the validator so its known why argument fails Modified Paths: -------------- trunk/octave-forge/main/general/inst/@inputParser/subsref.m Modified: trunk/octave-forge/main/general/inst/@inputParser/subsref.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-14 08:03:43 UTC (rev 10433) +++ trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-14 08:17:51 UTC (rev 10434) @@ -89,7 +89,7 @@ [name, inPar.copy] = shift (inPar.copy); [value, args] = shift (args); if ( !feval (inPar.Required.(name).validator, value) ) - error("%sargument '%s' failed validation %s", inPar.FunctionName, name, func2str (inPar.Required.(name).validator)); + error_invalid (inPar.FunctionName, name, inPar.Required.(name).validator); endif inPar.Results.(name) = value; endfor @@ -124,7 +124,7 @@ args = unshift (args, value); continue else - error("%sinvalid value for parameter '%s'", inPar.FunctionName, name); + error_invalid (inPar.FunctionName, name, inPar.Optional.(name).validator); endif else inPar.Results.(name) = value; @@ -175,7 +175,7 @@ if (!isempty (index)) [name, inPar.copy] = shift (inPar.copy, index); if ( !feval (inPar.(method).(name).validator, value)) - error("%sinvalid value for parameter '%s'", inPar.FunctionName, key); + error_invalid (inPar.FunctionName, key, inPar.(method).(name).validator); endif ## we use the name shifted from 'copy' instead of the key from 'args' in case ## the key is in the wrong case @@ -301,11 +301,16 @@ ## make sure that the given default value is actually valid ## TODO make sure that when using the default, it's only validated once if ( isa (val, 'function_handle') && !strcmpi (method, 'Required') && !feval (val, def) ) - error ("default value does not validate with '%s'", func2str (val) ); + error ("default value for '%s' failed validation with '%s'", name, func2str (val) ); endif endfunction +## this is just for consistency of error message +function error_invalid (prefix, name, val) + error("%sargument '%s' failed validation %s", prefix, name, func2str (val)); +endfunction + ################################################################################ ## very auxiliary functions ################################################################################ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |