Re: Args with multiple identical keywords

Sascha Alexander Jopen <[email protected]> Tue, 07 Aug 2012 13:44:48 +0200
Newsgroups gmane.network.routing.click
Message-ID <[email protected]>
Hello,

while using read_all_with() i found different parse method signatures in
the parsers AnyArg and IPAddressArg for parsing into Vectors. I propose
to change the parse() signature of AnyArg for Vectors, as well as the
parser call in base_read_all_with() to have the same order of the
arguments as all other parse() methods. This may break existing custom
parsers, however.

You can find the necessary changes in the attached patch, if you think
this is a reasonable change.

Regards,
Sascha


On 07/30/12 19:37, Eddie Kohler wrote:
> Yes, try Args::read_all_with().
> 
> Eddie
> 
> 
> On Mon, Jul 30, 2012 at 7:35 AM, Sascha Alexander Jopen
> <[email protected]> wrote:
>> Hey,
>>
>> is it possible to parse argument lists containing the same keyword
>> multiple times, having each occurence of the keyword values assigned to
>> another variable?
>>
>> For example, would like to parse a configuration like this:
>>
>> SomeElement(FIRSTKEYWORD 1, FIRSTKEYWORD 2, ..., SECONDKEYWORD a,
>> SECONDKEYWORD b, ...);
>>
>> Currently only the last value of a keyword group is parsed and returned
>> as a result after consume() and all additional identical keyword
>> arguments are removed from the configuration string.
>>
>> The only solution i see so far is having a single keyword and
>> concatenating all values into a single argument to this keyword. This
>> keyword is then parsed as a string, splitting the string and passing the
>> parts to additional argument parsers of the right type.
>>
>> Does anybody know a better solution, which can directly be handled by
>> the argument parser?
>>
>> Regards,
>> Sascha
>> _______________________________________________
>> click mailing list
>> [email protected]
>> https://amsterdam.lcs.mit.edu/mailman/listinfo/click

_______________________________________________
click mailing list
[email protected]
https://amsterdam.lcs.mit.edu/mailman/listinfo/click
click-read_all_with.diff (text/plain, 827 B)
diff --git a/include/click/args.hh b/include/click/args.hh
index dd3174e..6039b6b 100644
--- a/include/click/args.hh
+++ b/include/click/args.hh
@@ -686,7 +686,7 @@ class Args : public ArgContext {
 	Slot *slot_status;
 	int read_status = -1;
 	while (String str = find(keyword, flags, slot_status)) {
-	    postparse(parser.parse(str, *this, variable), slot_status);
+	    postparse(parser.parse(str, variable, *this), slot_status);
 	    read_status = (read_status != 0) && _read_status;
 	    flags &= ~mandatory;
 	}
@@ -1174,7 +1174,7 @@ class AnyArg { public:
 	result = str;
 	return true;
     }
-    static bool parse(const String &str, const ArgContext &, Vector<String> &result) {
+    static bool parse(const String &str, Vector<String> &result, const ArgContext &) {
 	result.push_back(str);
 	return true;
     }