case & string
Ondrej Zajicek
santiago at crfreenet.org
Tue Oct 8 17:07:44 CEST 2024
On Tue, Oct 08, 2024 at 12:16:42PM +0300, Mikhail Mayorov wrote:
> Hi!
>
> I try use CASE and string variable and a have error.... I checked User's
> guide 2.0 <https://bird.network.cz/?get_doc&f=bird.html&v=20>.... CASE use
> operator ~. This operator applies to string variables. What am I doing
> wrong?
Hi
Seems like a discrepancy between functionality and documentation.
The description of 'case' [1] says:
The expression after case can be of any type which can be on the left
side of the ~ operator and anything that could be a member of a set is
allowed
But in fact, only the second part is true, only values that could be
members of sets are allowed (with the exception of prefixes, as prefix
sets are implemented in a different way). According to [2], that are:
int | pair | quad | ip | prefix | ec | lc | enum
We probably should fix 'case' for prefixes. Looking at it now, there is
also vpnrd, which is allowed in set, but undocumented, and not in switch.
In principle, we could extend sets / case to contain strings / bytesrings,
but i do not really see use case.
[1] https://bird.network.cz/?get_doc&v=20&f=bird-5.html#control-structures
[2] https://bird.network.cz/?get_doc&v=20&f=bird-5.html#type-set
> [root at wine etc]# cat 123.conf && bird -c ./123.conf -p
> function teststring(string myvar) -> bool
> {
> case myvar {
> "text A" : print "A"; return true;
> "text B" : print "B"; return true;
> "text C" : print "C"; return true;
> else : print "unknown"; return false;
> }
> }
> bird: ./123.conf:4:12 syntax error, unexpected TEXT
>
> --
>
> Regards,
> Mikhail Mayorov
--
Elen sila lumenn' omentielvo
Ondrej 'Santiago' Zajicek (email: santiago at crfreenet.org)
"To err is human -- to blame it on a computer is even more so."
More information about the Bird-users
mailing list