[SR-Dev] git:andrei/switch: script parsing: C style switch() & case support

Daniel-Constantin Mierla miconda at gmail.com
Thu Feb 5 19:55:47 CET 2009


On 02/05/2009 05:52 PM, Andrei Pelinescu-Onciul wrote:
> On Feb 05, 2009 at 10:48, Henning Westerholt <henning.westerholt at 1und1.de> wrote:
>   
>> On Wednesday 04 February 2009, Daniel-Constantin Mierla wrote:
>>     
>>> 2) it can shorten the script and save some ifs:
>>>
>>> switch(a) {
>>>  case v1:
>>>        something;
>>>  case v2:
>>>        something else;
>>> break;
>>> }
>>>       
>> Hi all,
>>
>> this is also a big advantage for me, as if your script gets too long its much 
>> harder to debug and understand.
>>
>>     
>>> It could be a sswitch (although I would prefer single name to avoid
>>> confusions) if breaks logic for integer optimizations.
>>>       
>> Having two different switch statements is IMHO really confusing.
>>     
>
>
> It's like the operators: we either have different switch() for strings
>  and integers or we have typed variables. Without this restrictions one
>  cannot optimize (IMO we should have both since that would allow for
>  much better type checking at startup -> a lot of possible script errors
>  can be easily indentified => more user friendly).
>   

What if we decide what type of case value is by the first 'case'? If 
first one is integer, then all should be integers and the 'switch' will 
have integer optimizations. If not integer, then expect only strings or 
regular expressions (which will be an useful addition) with the main 
benefit of a nice-looking config file.

Cheers,
Daniel

> How about using match() for sswitch()?
> Also should we use only strings or REs too, e.g.:
>
> match($v){
>     case "foo":
>     case /[0-9]+/:
>     ...
> }
>
>
> Andrei
>
> _______________________________________________
> sr-dev mailing list
> sr-dev at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>
>   

-- 
Daniel-Constantin Mierla
http://www.asipto.com




More information about the sr-dev mailing list