Functions with 2+ arguments
Hoi folks, Consider the following two functions in Bird v2.15.1: function test_ok(int var1) -> bool { if (bgp_large_community ~ [ (50869,1000,var1), (50869,2000,8298) ]) then return true; return false; } function test_nok(int var1; int var2) -> bool { if (bgp_large_community ~ [ (50869,1000,var1), (50869,2000,var2*)* ]) then return true; return false; } The first one parses fine, but the second function yields a parse error on bird: __filename__:199:66 Expression of type int expected Position 199:66 is the closing parenthesis directly after var2. I colored that paren red above. Is my construct or syntax incorrect in the test_nok() case? groet, Pim -- Pim van Pelt PBVP1-RIPE -https://ipng.ch/
On Tue, Oct 22, 2024 at 09:34:59PM +0200, Pim van Pelt via Bird-users wrote:
Hoi folks,
Consider the following two functions in Bird v2.15.1:
function test_ok(int var1) -> bool { if (bgp_large_community ~ [ (50869,1000,var1), (50869,2000,8298) ]) then return true; return false; }
function test_nok(int var1; int var2) -> bool { if (bgp_large_community ~ [ (50869,1000,var1), (50869,2000,var2*)* ]) then return true; return false; }
The first one parses fine, but the second function yields a parse error on bird: __filename__:199:66 Expression of type int expected
Hi Not sure why you get the parse error, when i tried that, function test_nok() got parsed just fine. The bigger issue is that neither test_ok() nor test_nok() should parse, as sets are required to be constants, so only contant expressions (including constants defined by 'define') should be allowed in them, not local variables. The error is properly generated in case of: function test_nok(int var1; int var2) -> bool { if (bgp_local_pref ~ [ var1, var2 ]) then return true; } Parse error filter/test.conf, line 1903: Constant name required But not in more complex expressions like: function test_nok(int var1; int var2) -> bool { if (bgp_local_pref ~ [ (var1 + 1), (var2 + 1) ]) then return true; } (or the large community constructor like in your case.) Just use: { if ((50869,1000,var1) ~ bgp_large_community) || ((50869,2000,var2) ~ bgp_large_community) then return true; } -- Elen sila lumenn' omentielvo Ondrej 'Santiago' Zajicek (email: santiago@crfreenet.org) "To err is human -- to blame it on a computer is even more so."
participants (2)
-
Ondrej Zajicek -
Pim van Pelt